Denary to Negative Binary Conversion
Two's complement is the method computers use to store signed integers — whole numbers that can be positive, zero or negative — in binary using a fixed number of bits.
An unsigned integer stores only zero and positive values: in eight bits it covers 0 to 255. A signed integer uses the same eight bits but uses half of the 256 patterns for negative values, so patterns with a 1 in the leftmost bit mean a negative value when read as two's complement. This is why the same pattern can mean one value when read as unsigned and another when read as signed.
With eight-bit two's complement, every value, positive or negative, is written as exactly eight bits, so you keep any leading zeros or leading ones. A fixed width matters because the processor needs to know how many bits belong to each number.
In an eight-bit two's complement number, the leftmost bit is the sign bit. A 0 there means the value is zero or positive; a 1 means it is negative.
| Eight-bit pattern | Sign bit | Read as unsigned | Read as two's complement |
|---|---|---|---|
| 01100100 | 0 | 100 | +100 |
| 11000111 | 1 | 199 | a negative value |
A negative value is not made by simply changing the leftmost bit of its positive pattern to 1 and leaving the rest unchanged; that idea is sign and magnitude, and it is not two's complement. Here the bits are arranged together as one pattern so the computer can add and subtract positive and negative values using the same circuits it already has. You can find the exact pattern for a negative number using the flip-and-add-one method.
Because the leftmost bit gives the sign, eight-bit two's complement has fewer positive patterns available than eight-bit unsigned.
Edexcel GCSE Computer Science · Denary to Negative Binary Conversion
Edexcel GCSE Computer Science · Binary Shifts