Binary-Octal-Hex Unit
by Mr. C. Monroe, Heritage High School
Part : Binary Numbers

Vocabulary
 

Place values are powers of 2
 
 
 
 0
---
 27
 1
---
 26
 1
---
 25
 0
---,
 24
 1
---
 23
 0
---
 22
 1
---
 21
 1
---
 20
Place Value
 128
64 
32 
16 
bit
(bits are named 
by their power)
 7

 
To evaluate, add place values that have a 1:
 64
 32
  8
  2
+ 1
---
107
Now you try this:
Enter the value of 1011,0110



To convert to binary,  subtract all place values that "fit".  Those that "fit" get a 1, the rest get 0's.
 
 
Example:  213 (decimal, or base ten)
  ~ start with the largest place value and work down
  ~ subtract to find all that "fit" and give them 1's
 213
-128
----
85
-64
----
21
-16
----
5
-4
----
1
-1
----
0
   
 1
---
128
 1
---
 64
 0
---
 32
 1
---,
 16
 0
---
 8
 1
---
 4
 0
---
 2
 1
---
 1
 
             
The resulting binary number is 1101,0101.
Now you try this:
Enter the binary equivalent of 165 (be sure to use a comma)

The largest binary number using 8 bits is 1111,1111 which equals 255d.


Adding Binary Numbers

Addition Facts:
 
 0 
+0
--
 0
 0 
+1
--
 1
 1 
+0
--
 1
 1 
+1
--
10
~when 1 and 1 are added, the result is 0 and we carry the 1.

Examples of adding 1 to a binary number:
 1011,0110
+        1
 ---------
 1011,0111
 1011,0111
+        1
 ---------
 1011,1000
 0011,1111
+        1
 ---------
 0100,0000
To represent negatives, we use the largest bit (bit "7") as the sign bit.  If it has a 1, the number is negative.

This limits the largest possible positive integer to 0111,1111, which equals 127d.

To find the negative of a binary number,

  1. swap the 1's and 0's
  2. add 1
Examples of negating a binary number:
                  0110,0101
swap 1's and 0's:  1001,1010
add 1:                     1
                   ---------
                  1001,1011
  0000,0000
  1111,1111
          1
  ---------
1,0000,0000
The extra 1 is called overflow and
  must be discarded.
Now you try this:
Enter the negation of 1011,0110 (be sure to use a comma)

To convert a negative decimal value (-1 to -127) to binary,

  1. convert its absolute value to binary
  2. negate the binary
    1. swap the 1's and 0's
    2. add 1
Example:  Convert -119 to binary.
Step 1 - convert its absolute value to binary Step 2 - negate the binary
The absolute value of -119 is 119. 
119 in binary is 0111,0111
 0111,0111
 1000,1000
+        1
 ---------
 1000,1001
Thus, -119 in binary is 1000,1001.

Now you try this:

Convert these negative numbers to binary (be sure to use a comma)
-25 
-1 
-127 


Larger Integers

Part 2