Do you know?
[BOTH] Number systems and complements - part 2
- Fact 1 of 12🔢
2's complement formula for N bits
2's complement of x in N bits = 2^N − x. Why: one formula gives negatives, so one adder handles everything. Example: 8-bit −5 = 256 − 5 = 251 = 11111011. Recall: formula for N-bit 2's complement?
- Fact 2 of 12🔄
Quick method: invert bits, then add 1
To get 2's complement, flip every bit, then add 1. Why: it is the fast hand method for negatives. Example: 5 = 00000101, flip gives 11111010, add 1 gives 11111011 (−5). Recall: what do you add after flipping bits?
- Fact 3 of 12➖
Subtraction using only an adder
A − B = A + (2's complement of B). Why: the adder circuit needs no separate subtractor, which saves hardware. Example: 9 − 3 = 00001001 + 11111101 gives 00000110 = 6, with the carry dropped. Recall: subtraction becomes addition of what?
- Fact 4 of 12📏
8-bit signed range: −128 to +127
An 8-bit 2's complement number runs from −128 to +127. Why: the pattern 10000000 is the extra negative value. Example: a 1-byte signed value stored in a microcontroller register. Recall: smallest 8-bit signed value?
- Fact 5 of 12🧮
Signed range formula for N bits
N-bit 2's complement range is −2^(N−1) to 2^(N−1) − 1. Why: half the patterns are negative and the other half are zero or positive. Example: 16-bit gives −32768 to 32767. Recall: 16-bit signed maximum?
- Fact 6 of 12➕
Sign bit: the leftmost bit
In signed numbers, the leftmost bit (MSB) is the sign bit. Why: 0 means positive and 1 means negative, so you check it first. Example: 11001010 is negative, while 01001010 is positive. Recall: which bit is the sign bit?
- Fact 7 of 120️⃣
2's complement has only one zero
2's complement has one zero, 00000000. Why: 1's complement and sign-magnitude have two zeros, +0 and −0, which wastes a pattern. Example: no confusing −0 result in the ALU. Recall: how many zeros does 2's complement have?
- Fact 8 of 12⚠️
Overflow: 127 + 1 becomes −128
In 8-bit 2's complement, 01111111 + 00000001 = 10000000, which is −128. Why: the true result 128 is out of range, so the sign flips wrongly. Example: like an odometer rolling over, but the sign flips. Recall: 127 + 1 in 8-bit gives?
- Fact 9 of 12🔁
Sign extension keeps the value
To widen a signed number, copy the sign bit into every new left bit. Why: the value stays the same. Example: 8-bit −5 (11111011) becomes 1111111111111011 in 16 bits. Recall: which bit gets copied?
- Fact 10 of 12🔢
BCD: 4 bits per decimal digit
Binary-Coded Decimal (BCD) writes each decimal digit 0 to 9 as its own 4-bit group. Why: each digit stays easy to read and convert. Example: digital meter and calculator displays often use BCD. Recall: bits needed per decimal digit in BCD?
- Fact 11 of 12🧾
BCD of 42 is 0100 0010
Each digit is coded separately: 4 becomes 0100 and 2 becomes 0010. Why: the 8421 weights are 8, 4, 2, 1 in each group. Example: 42 in plain binary is 101010, but in BCD it is 0100 0010. Recall: BCD code of 42?
- Fact 12 of 12🚫
BCD: 1010 to 1111 are invalid
In 8421 BCD, the patterns 1010 to 1111 (10 to 15) are not valid digits. Why: a valid BCD digit is always 0000 to 1001. Example: a digital display would show an error for these codes. Recall: which 4-bit codes are invalid in BCD?
