Menu

Denary to Negative Binary Conversion

Two's Complement Range and Overflow

An 8-bit two's complement number always uses exactly eight bits, and that fixed width limits which denary values it can hold. The range is -128 to +127 inclusive: 256 different bit patterns, one for each value from -128 up to +127.

Why the range is not symmetrical

The leftmost bit decides the sign. Every pattern that starts with 1 is negative, and there are 128 such patterns, so the negative values run from -128 up to -1. The 128 patterns that start with 0 cover zero and the positive values 0 to +127. Zero takes one pattern of its own, which is why you get 127 positive values but 128 negative ones.

Denary valueInside the range?Reason
-128YesThe smallest value
0YesZero is included
+127YesThe largest value
+128NoOverflow: outside the range

-128 fits, but +128 does not

The bottom of the range is -128, so -128 has a valid code. The value +128 is outside the range. Eight bits have 256 codes and all of them are already used, so there is no spare code for +128. Trying to store a value outside -128 to +127 in eight bits is called overflow.

When a calculation overflows

Overflow can happen even when the two values being added are both inside the range. For example, 90 and 90 are both valid, but 90 + 90 = 180, which is outside -128 to +127. In eight bits, 90 is 01011010. Adding it to itself gives the eight-bit result 10110100. Read as a two's complement number, that pattern means -76, not +180. The answer has wrapped round to a different value, so the result is not a valid larger positive answer.

A bar from -128 to +127 split at the sign bit: patterns starting 1 are -128 to -1, patterns starting 0 are 0 to +127, with +128 as overflow. An arc shows 90 + 90 = 180 wrapping round to -76.

Adding 1 to the largest positive value, +127, does something similar: the carry ripples through every 1 bit, the sign bit turns to 1, and the pattern is read as the smallest negative value instead of a bigger positive one. That too is an overflow.

Practise this