Vocabulary
|
|
0 --- 27 |
1 --- 26 |
1 --- 25 |
0 ---, 24 |
1 --- 23 |
0 --- 22 |
1 --- 21 |
1 --- 20 |
Place Value |
128 |
64 |
32 |
16 |
8 |
4 |
2 |
1 |
bit (bits are named by their power) |
7 |
6 |
5 |
4 |
3 |
2 |
1 |
0 |
| To evaluate, add place values that have a 1: |
64 32 8 2 + 1 --- 107 |
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. |
|||||||||
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 |
| 1011,0110
+ 1 --------- 1011,0111 |
1011,0111
+ 1 --------- 1011,1000 |
0011,1111
+ 1 --------- 0100,0000 |
This limits the largest possible positive integer to 0111,1111, which equals 127d.
To find the negative of 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. |
To convert a negative decimal value (-1 to -127) 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 |
|
|
|
Now you try this:
Larger Integers