Binary Math
In binary only two symbols are available, 0 and 1.
When we add 1 + 1 in binary, we must "carry the 1" to the next available place - just like in the decimal system when we add 9 + 1.
0000 = 0 0001 = 1 0010 = 2 (1 + 1 = 0; carry the 1) 0011 = 3 0100 = 4 (1 + 1 = 0; carry the 1; 1 + 1 = 0; carry the 1) 0101 = 5 0110 = 6 0111 = 7 1000 = 8
The pattern we see is that every bit represents a power of 2.
| Power | 23 | 22 | 21 | 20 |
| Value | 8 | 4 | 2 | 1 |
We can construct any number using these values.
| Bit | 0 | 1 | 0 | 1 | |
| Value | 0 | 4 | 0 | 1 | = 5 |
| Bit | 1 | 0 | 1 | 1 | 1 | |
| Value | 16 | 0 | 4 | 2 | 1 | = 23 |
Drill¶
This drill requires pen and paper or whiteboard.
* What is 011011 in decimal?
* Write the number 28 in binary. How? Find the largest power-of-2 number you can have in 28. Subtract it. Find the next-largest. Repeat this pattern.
* Write the number 17 in binary.
* Write the number 43 in binary.
Negative Numbers¶
To get the binary representation of a negative number, follow these steps: * Take the binary positive number. * Invert the bits * Add 1.
For example, the number -1:
* 00000001
* 11111110
* 11111111 = -1
For the number -15:
* 00001111
* 11110000
* 11110001 = -15