An unsigned 8-bit word ranges from 0 to 255. In two’s complement, the highest bit has weight −128 instead of +128, producing a range of −128 to 127. The bit pattern 11111111 therefore means 255 unsigned or −1 signed.
To negate a word modulo 2^w, flip all w bits and add one. The minimum signed value is a special case: its negated word has the same bit pattern, because its positive counterpart does not fit in the signed range.
Truncation keeps the low bits. Sign extension copies the sign bit into new high positions. Unsigned arithmetic wraps modulo 2^w; signed overflow in C is undefined. A word-model result must never be mistaken for a guarantee about arbitrary signed C code.
Explain it before you practise
Look away from the example. Explain why it works and predict a boundary case. Then check your reasoning.
Why does negating 10000000 in the 8-bit word model give the same pattern? Is this a guarantee about signed C arithmetic?
Check your reasoning
The pattern means −128 signed, but +128 is outside the signed 8-bit range. Modulo 256, −128 and 128 have the same low eight bits. The word model wraps explicitly; signed overflow in C is undefined.
Cement this knowledge
Solve ten fresh questions without the worked example. Mistakes return during the session; spaced review helps you recall the method on later days.
Practice this topic →