Adding in binary
Add from the right, column by column, just as in denary.
| Sum | Write | Carry |
|---|---|---|
| 0 + 0 | 0 | 0 |
| 0 + 1 | 1 | 0 |
| 1 + 1 | 0 | 1 |
| 1 + 1 + 1 | 1 | 1 |
Always check in denary: convert both numbers, add, and convert back.
Overflow happens when the result needs more bits than there are. Adding two 8-bit numbers whose total is over 255 produces a ninth bit; in an 8-bit register it is lost and the stored answer is wrong.
Binary shifts
A left shift moves every bit left and fills the gap on the right with 0. Each place multiplies the value by 2.
A right shift moves every bit right, filling with 0 on the left. Each place divides by 2, and any 1s shifted off the right-hand end are lost, so the result rounds down.
- 0001 0110 is 22.
- Left shift 2 places: 0101 1000 is 88 (22 × 4).
- Right shift 1 place: 0000 1011 is 11 (22 ÷ 2).
If a 1 is shifted off the left of an 8-bit number, the result is no longer the value × 2.
Add two numbers
Watch the carries, then check in denary.