Binary arithmetic
| English | Chinese | Pinyin |
|---|---|---|
| register | 寄存器 | jì cún qì |
| overflow | 溢出 | yì chū |
| two's complement | 补码 | bǔ mǎ |
| logical shift | 逻辑移位 | luó jí yí wèi |
| most significant bit | 最高有效位 | zuì gāo yǒu xiào wèi |
Doing maths with 1s and 0s
- 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.

An 8-bit place-value chart. The 1s sit under the values that add up to 150 (128 + 16 + 4 + 2).
Binary arithmetic
byte = Σ place values
See how an 8-bit pattern stores a number from 0 to 255.
Add the binary numbers 0101 + 0011. Give the 4-bit result.
5 + 3 = 8 = 1000.
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$.

Each hexadecimal digit becomes its own 4-bit group (nibble): F = 1111, 0 = 0000, 8 = 1000.
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).
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.

The most significant bit is worth −128, so 11011000 = −128 + 64 + 16 + 8 = −40
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
- 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