Binary arithmetic
Binary arithmetic
- Computers add, shift and store negative numbers — all in binary.
- An 8-bit register has limits, so results can overflow.
- Two's complement lets us store negatives.
Binary addition and overflow
- Add column by column from the right, carrying a 1: $1+1 = 10$ (write 0, carry 1).
- Example:
01110110(118) +00110000(48) =10100110(166). - An 8-bit register holds 0–255. A result above 255 needs a 9th bit that won't fit — this is overflow, and the stored answer is wrong.
Practice
Add the binary numbers 0101 + 0011. Give the 4-bit result.
5 + 3 = 8 = 1000.
Practice
Overflow in an 8-bit register happens when:
An 8-bit register holds 0–255; a bigger result needs a 9th bit that cannot fit, so it is lost.
Logical binary shift
- A logical shift moves all bits left or right; bits off the end are lost and zeros fill the gap.
- A left shift multiplies by 2 per place; a right shift divides by 2 per place.
- Example:
00110101(53) left-shifted by 2 →11010100(212) = $53 \times 4$.
Practice
A logical left shift by 1 multiplies an unsigned number by what?
Each left-shift place multiplies by 2 (a right shift divides by 2).
Practice
00110101 is 53. After a logical left shift of 2 places, what denary value does it hold?
Left shift by 2 = ×4: 53 × 4 = 212 (11010100).
Two's complement (negatives)
- In two's complement, the most significant bit has a negative value:
-128 64 32 16 8 4 2 1. - MSB 0 → positive; MSB 1 → negative.
- To make a number negative: write the positive, flip every bit, then add 1. e.g. $+40$ =
00101000→ flip11010111→ +1 →11011000= $-40$. - Range of 8-bit two's complement: −128 to +127.
Practice
What is the most negative value an 8-bit two's complement number can store?
The MSB is worth −128, so the range is −128 to +127.
You've got it
Key idea
- add binary with carries; overflow = result needs a 9th bit an 8-bit register can't hold (0–255)
- logical shift: left = ×2, right = ÷2 per place; bits off the end are lost
- two's complement: MSB worth −128; flip bits and add 1 to negate; range −128 to +127