Binary arithmetic
Introduzido| English | Significado |
|---|---|
| register/ˈredʒɪstə/ | registrador |
| overflow/ˌəʊvəˈfləʊ/ | transbordamento |
| two's complement/tuːz ˈkɒmplɪmənt/ | complemento de dois |
| logical shift/ˈlɒdʒɪkl ʃɪft/ | deslocamento lógico |
| most significant bit/məʊst sɪɡˈnɪfɪkənt bɪt/ | bit mais significativo |
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.


Aritmética binária
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.
Dificuldade 1/5 · Moedas 100 + pequeno bônus na primeira conclusão hoje
5 + 3 = 8 = 1000.
Overflow in an 8-bit register happens when:
Dificuldade 1/5 · Moedas 100 + pequeno bônus na primeira conclusão hoje
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$.

A logical left shift by 1 multiplies an unsigned number by what?
Dificuldade 2/5 · Moedas 140 + pequeno bônus na primeira conclusão hoje
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?
Dificuldade 2/5 · Moedas 140 + pequeno bônus na primeira conclusão hoje
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.

What is the most negative value an 8-bit two's complement number can store?
Dificuldade 2/5 · Moedas 140 + pequeno bônus na primeira conclusão hoje
The MSB is worth −128, so the range is −128 to +127.
Worked example: an overflow, then a negative
An 8-bit register adds 11001000 (200) and 01100100 (100). Then write $-20$ in 8-bit two's complement.
- The true sum is 300, which needs 9 bits:
1 00101100. The 9th bit is lost, so the register stores00101100= 44. This is an overflow error: 300 is above the limit of 255. - $+20$ =
00010100. Flip every bit:11101011. Add 1:11101100. Check: $-128 + 64 + 32 + 8 + 4 = -20.$
00010110 (22) is shifted one place to the left. What denary value does it now hold?
Dificuldade 2/5 · Moedas 140 + pequeno bônus na primeira conclusão hoje
One left shift multiplies by 2: 00101100 = 44.
In 8-bit two's complement, what is 11111111?
Dificuldade 1/5 · Moedas 100 + pequeno bônus na primeira conclusão hoje
$-128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = -1$.
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