Math Fundamentals18 sections · 814 units
Open in Course

Reading Two's Complement

Decoding negative values

To read a two's complement number, check the leftmost bit. If 0, treat it as unsigned binary. If 1, it is negative: flip all bits, add 1, then negate the result.

Example: What is 1111101111111011 in 8-bit two's complement? Leftmost bit is 1, so it is negative. Flip: 0000010000000100. Add 1: 0000010100000101 (which is 5). Negate: 5-5. Result: 11111011=511111011 = -5.

Shortcut: the leftmost 1 in a negative number is worth 2n1-2^{n-1}, and the rest are positive powers. For 1111101111111011: 128+64+32+16+8+2+1=5-128 + 64 + 32 + 16 + 8 + 2 + 1 = -5. With practice, you can read two's complement as fast as unsigned.