This page is the drill-ground for Two's complement signed numbers . We will hit every kind of situation the topic can throw at you — positive, negative, zero, the awkward edge values, subtraction, overflow, a real-world word problem, and an exam-style trap. Nothing here contradicts the parent note; it goes deeper by making you work each case by hand.
Before you start, you only need three facts from the parent, restated in plain words:
Recall The three tools we reuse everywhere
Weight rule (decode): the top bit is worth − 2 n − 1 ; every other bit b i is worth + 2 i . To decode, add up the weights of the bits that are 1.
Negate rule (encode − x ): flip every bit, then add 1 (because x + x ˉ = 2 n − 1 , so x ˉ + 1 = 2 n − x ≡ − x ( mod 2 n ) ).
Overflow rule: for signed add, overflow happens when carry into the top bit = carry out of it: C n − 1 ⊕ C n = 1 .
Here x ˉ means "bitwise NOT of x " (turn every 0 into 1 and vice-versa), and n is how many bits we have. Unless stated we use n = 8 , so the range is [ − 128 , + 127 ] .
Every problem in this topic is one of these cells. The examples below are tagged with the cell they cover, so you can see the whole map is filled.
#
Case class
What's tricky about it
Example
A
Encode a positive number
Just write the binary — sign bit stays 0
Ex 1
B
Encode a negative number
Flip-and-bump
Ex 1
C
Decode a bit-pattern with MSB = 0
Behaves like plain unsigned
Ex 2
D
Decode a bit-pattern with MSB = 1
Top bit is − 128 , not + 128
Ex 2
E
Zero and its "double" 10000000
Only one zero; the extreme negative
Ex 3
F
Add two numbers, no overflow , carry-out dropped
Discard carry safely
Ex 4
G
Subtraction as add-the-negative
a − b = a + ( − b )
Ex 5
H
Overflow , two positives
Same-sign in, opposite-sign out
Ex 6
I
Overflow , two negatives
The symmetric failure
Ex 7
J
Degenerate negate : − ( − 128 )
Has no positive twin
Ex 8
K
Real-world word problem
Translate a story into signed bytes
Ex 9
L
Exam twist : different bit-width n = 4
Rules scale, numbers don't
Ex 10
The number line above is the mental picture for all these cells: eight-bit patterns laid on a circle, the top half re-labelled as negatives.
+ 37 and − 37 in 8 bits
Forecast: guess now — will the two answers look like "mirror images", or something stranger? (Trap: they are not simple mirrors.)
Encode + 37 :
Break 37 into powers of two: 32 + 4 + 1 = 2 5 + 2 2 + 2 0 .
Why this step? Decoding/encoding positives is just ordinary binary; the sign bit will be 0 so no special weight is involved.
Write it: 00100101.
Why? Bits 5, 2, 0 are set; top bit 0 confirms it's non-negative.
Encode − 37 : apply flip-and-bump to 00100101.
3. Flip every bit: 11011010.
Why? x ˉ = 2 n − 1 − x ; this gets us to "one short of − x ".
4. Add 1: 11011010 + 1 = 11011011.
Why? x ˉ + 1 = 2 n − x ≡ − x . Now the pattern is − 37 .
Verify: decode 11011011 by weights:
− 128 + 64 + 16 + 8 + 2 + 1 = − 128 + 91 = − 37. ✓
Notice 00100101 and 11011011 are not mirror images — that's the forecast trap.
01011010 and 11011010 (8-bit)
Forecast: the two patterns differ only in the top bit. Will the values differ by exactly 128 , or by something else?
Decode 01011010 (MSB = 0):
MSB is 0 → number is non-negative, top bit weight contributes 0 .
Why? The − 2 7 weight only applies when that bit is 1.
Sum the set bits: 64 + 16 + 8 + 2 = 90 .
Why? Plain positional weights 2 6 , 2 4 , 2 3 , 2 1 .
Decode 11011010 (MSB = 1):
3. MSB is 1 → include the negative weight − 128 .
Why? This is the whole point of two's complement — the top bit's weight is − 2 7 .
4. Sum: − 128 + 64 + 16 + 8 + 2 = − 128 + 90 = − 38 .
Verify: the two answers are 90 and − 38 . Their difference is 90 − ( − 38 ) = 128 . ✓ Flipping the top bit alone changes the value by exactly 2 7 = 128 (from + 128 to − 128 weight is a swing of 256 ... wait — here we only added the negative weight, we didn't remove a positive one, so the swing is 128 , not 256 ). This is the subtle bit the forecast baits.
Common mistake "Setting the top bit subtracts 256."
That would be true only if the top bit had been + 128 and now becomes − 128 (a 256 swing). But in decoding a fixed pattern you just add the weight of whichever bits are 1. Here bit 7 alone is worth − 128 , so the two patterns differ by 128 , not 256 .
00000000 and 10000000?
Forecast: sign-magnitude has a "+ 0 " and a "− 0 ". Does two's complement?
Decode 00000000: all weights off → 0 .
Why? No bits set, nothing to add.
Try to build "− 0 " by flip-and-bump of 0 : flip → 11111111, add 1 → 1 00000000. Drop the 9th bit → 00000000.
Why we drop it? The carry-out is worth 2 8 ≡ 0 ( mod 2 8 ) ; invisible in 8 bits.
So − 0 = 0 : there is one zero. The freed pattern 10000000 is used for an extra negative.
Decode 10000000: − 128 + 0 = − 128 .
Why − 128 ? Only the top bit is set, worth − 2 7 .
Verify: the smallest value is − 128 = − 2 7 (matches range floor), and − 0 collapsed to 0 . ✓ Single zero confirmed.
70 + ( − 90 ) in 8-bit
Forecast: result should be − 20 . Will there be a carry-out? Does it matter?
Encode 70 = 64 + 4 + 2 = 01000110.
Encode − 90 : + 90 = 64 + 16 + 8 + 2 = 01011010; flip → 10100101; +1 → 10100110.
Why? Flip-and-bump gives − x .
Add the bytes:
01000110 (70)
+ 10100110 (-90)
= 11101100
Why straight binary add? One adder handles signed values — the negative weight is baked into the pattern.
No carry-out here (top bits 0+1, no overflow past bit 7). Decode result 11101100:
− 128 + 64 + 32 + 8 + 4 = − 128 + 108 = − 20 . ✓
Verify (overflow check): carry into MSB C 7 and carry out C 8 — both 0 , 0 ⊕ 0 = 0 , no overflow. Answer − 20 is in range. ✓
45 − 100 in 8-bit
Forecast: 45 − 100 = − 55 . We never build a "subtractor" — we add the negative.
Encode 45 = 32 + 8 + 4 + 1 = 00101101.
Encode − 100 : + 100 = 64 + 32 + 4 = 01100100; flip → 10011011; +1 → 10011100.
Add:
00101101 (45)
+ 10011100 (-100)
= 11001001
Why add instead of subtract? a − b ≡ a + ( − b ) , and − b is a normal pattern.
Decode 11001001: − 128 + 64 + 8 + 1 = − 128 + 73 = − 55 . ✓
Verify: 45 + ( − 100 ) = − 55 , in range, no carry-out to worry about. Overflow check: C 7 = 0 , C 8 = 0 ⇒ no overflow. ✓
80 + 70 in 8-bit signed
Forecast: 150 is bigger than 127 — it can't fit! Watch what the hardware "reports".
Encode 80 = 64 + 16 = 01010000; 70 = 64 + 4 + 2 = 01000110.
Add:
01010000 (80)
+ 01000110 (70)
= 10010110
Decode 10010110: − 128 + 16 + 4 + 2 = − 128 + 22 = − 106 .
Why is it negative?! Two positives produced a top-bit 1 — impossible for a true sum, so this is a wrong answer flagged as overflow .
Overflow flag: carry into MSB C 7 = 1 (bits below overflowed up), carry out C 8 = 0 . 1 ⊕ 0 = 1 → overflow .
Why this test? Same-sign operands giving opposite-sign result is exactly the definition of signed overflow.
Verify: true answer 150 exceeds 127 ; hardware shows − 106 ; and 150 − 256 = − 106 , confirming the mod-2 8 wrap. Overflow correctly detected. ✓
( − 80 ) + ( − 70 ) in 8-bit signed
Forecast: true value − 150 is below − 128 — underflow (still called "overflow" for the flag).
Encode − 80 : + 80 = 01010000; flip 10101111; +1 → 10110000.
Encode − 70 : + 70 = 01000110; flip 10111001; +1 → 10111010.
Add:
10110000 (-80)
+ 10111010 (-70)
= 1 01101010 (carry-out = 1)
Keep 8 bits → 01101010.
Decode 01101010: 64 + 32 + 8 + 2 = 106 .
Why positive?! Two negatives yielded a positive → overflow.
Flag: carry into MSB C 7 = 0 , carry out C 8 = 1 . 0 ⊕ 1 = 1 → overflow .
Verify: true − 150 ; hardware shows + 106 ; and − 150 + 256 = 106 confirms the wrap. Note the carry-out here is 1 (present) yet the result is still wrong — proving that carry-out alone never signals signed overflow ; the XOR test does. ✓
− 128 in 8-bit
Forecast: you'd expect + 128 — but + 128 doesn't fit in 8-bit signed. Something must give.
− 128 = 10000000.
Flip: 01111111.
Add 1: 01111111 + 1 = 10000000.
Why does it loop back? + 128 would need weight + 2 7 , but the top bit's weight is − 2 7 , so + 128 has no valid pattern. Flip-and-bump lands back on − 128 .
Decode result 10000000: − 128 again.
Verify: − ( − 128 ) = − 128 in 8-bit — an overflow of negation, the single value that is its own negative besides 0 . This is exactly why the range is asymmetric: − 128 has no positive twin. ✓
Worked example A thermostat stores temperature as an 8-bit signed byte (°C). It reads
− 9° C outside, then the sun raises it by 15° C . What byte does it store, and what temperature does that decode to?
Forecast: − 9 + 15 = 6 . But we must do it in bytes to trust the hardware.
Encode − 9 : + 9 = 00001001; flip 11110110; +1 → 11110111.
Encode + 15 = 00001111.
Add:
11110111 (-9)
+ 00001111 (+15)
= 1 00000110 (carry-out dropped)
Keep 8 bits → 00000110.
Why drop the carry? It's worth 2 8 ≡ 0 ; invisible.
Decode 00000110: 4 + 2 = 6 .
Verify: stored byte 00000110 decodes to + 6° C , matching − 9 + 15 = 6 . Overflow check: C 7 = 1 , C 8 = 1 , 1 ⊕ 1 = 0 → no overflow, answer trustworthy. ✓ (Units: °C throughout.)
4-bit two's complement, compute 5 + 4 and decode the result. Also state the range.
Forecast: 9 won't fit in 4-bit signed (range only [ − 8 , + 7 ] ). Expect overflow.
Range for n = 4 : [ − 2 3 , 2 3 − 1 ] = [ − 8 , + 7 ] .
Why? Same formula, just n = 4 .
Encode 5 = 0101, 4 = 0100.
Add:
0101 (5)
+ 0100 (4)
= 1001
Decode 1001 (4-bit): top bit weight − 2 3 = − 8 , so − 8 + 1 = − 7 .
Why negative? Two positives gave top-bit 1 → overflow.
Flag: C 3 = 1 (carry into MSB), C 4 = 0 (out), 1 ⊕ 0 = 1 → overflow .
Verify: true 9 exceeds 7 ; hardware shows − 7 ; and 9 − 16 = − 7 confirms mod-2 4 wrap. The rules are identical to 8-bit — only n changed. ✓
Recall Self-test before moving on
Decode 11011011 (8-bit). ::: − 128 + 91 = − 37
Negate − 128 in 8-bit. ::: − 128 (overflow, no positive twin)
Does 10000000 mean "minus zero"? ::: No — it's − 128 ; two's complement has a single zero
80 + 70 in 8-bit signed gives what stored value, and is it valid? ::: 10010110 = − 106 ; overflow , invalid
Why is carry-out unreliable for signed overflow? ::: Ex 7 has carry-out = 1 yet is correct-shaped by carry only; use C n − 1 ⊕ C n
Parent: Two's complement signed numbers
Binary number system — every encode step is ordinary binary underneath
Sign-magnitude representation — where "− 0 " and mirror-image intuition come from (and fail here)
One's complement — flip-only, the step before the "+1"
Full adder — the single circuit doing all additions above
Modular arithmetic — why dropped carries and wrap-arounds are exact
Overflow and carry flags — the ALU status bits Ex 6, 7, 10 set