Арифметика двоичных чисел
| English | Русский |
|---|---|
| register/ˈredʒɪstə/ | регистром |
| overflow/ˌəʊvəˈfləʊ/ | переполнение |
| two's complement/tuːz ˈkɒmplɪmənt/ | дополнительный код |
| logical shift/ˈlɒdʒɪkl ʃɪft/ | логический сдвиг |
| most significant bit/məʊst sɪɡˈnɪfɪkənt bɪt/ | старший значащий бит |
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).
Арифметика двоичных чисел
байт = сумма позиций значений
Посмотрите, как 8-битный паттерн хранит число от 0 до 255.
Сложите двоичные числа 0101 + 0011. Дайте результат в 4 битах.
5 + 3 = 8 = 1000.
Переполнение в 8-битном регистре происходит, когда:
8-битный регистр хранит 0–255; больший результат требует 9-го бита, который не помещается, поэтому он теряется.
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.
Логический сдвиг влево на 1 умножает беззнаковое число на что?
Каждый сдвиг влево умножает на 2 (сдвиг вправо делит на 2).
00110101 равен 53. После логического сдвига влево на 2 позиции, какое десятичное значение он будет хранить?
Сдвиг влево на 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
Какое самое маленькое (наиболее отрицательное) значение может хранить 8-битное число в дополнении до двух?
Младший бит имеет вес −128, поэтому диапазон составляет от −128 до +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