Menu

Binary

Unsigned Binary to Negative Binary Conversion

Contents

  1. Two's Complement Place Values
  2. Converting Negative Denary to Two's Complement
  3. Two's Complement to Denary
  4. Alternative Two's Complement Method

In 8-bit two's complement every bit still has a place value, but the leftmost bit is worth -128 rather than 128. Reading left to right, the eight place values are -128, 64, 32, 16, 8, 4, 2 and 1. Any 1 bit adds its place value to the total; any 0 bit adds nothing.

The eight place values

Bit positionPlace value
7 (leftmost, the sign bit)-128
664
532
416
38
24
12
0 (rightmost)1

The leftmost bit is called the sign bit, and it really is part of the total. When it is 1 you start at -128; when it is 0 the value is zero or positive and you add only the ordinary values. A pattern with a 1 in the sign bit is always negative, because the other seven bits can add at most 64 + 32 + 16 + 8 + 4 + 2 + 1 = 127, which is never enough to climb back up to zero.

Converting without flipping any bits

Write down each place value under its bit, then add the values wherever a 1 appears. Take 11010010: the 1s sit in the -128, 64, 16 and 2 columns, so the value is -128 + 64 + 16 + 2 = -46. Try 11100111: -128 + 64 + 32 + 4 + 2 + 1 = -25. Because the sign bit can never be cancelled out, any pattern that begins with 1 sits somewhere from -128 up to -1, and any pattern that begins with 0 sits from 0 up to 127, so a single byte holds exactly 256 different values, from -128 up to 127, with no gaps.

Eight bit positions 7 to 0 with place values -128, 64, 32, 16, 8, 4, 2, 1, the sign bit marked, and 11010010 with its 1s adding -128 + 64 + 16 + 2 = -46.

Patterns with a 0 sign bit

A 0 in the sign bit means the -128 card is not counted, so you just add the positive values. For 01000111 that is 64 + 4 + 2 + 1 = 71. This is exactly the same number you would get reading the pattern as unsigned, because positive two's complement patterns are never changed.

Two's complement is the method computers use to store negative whole numbers in binary. To turn a negative denary number into its 8-bit two's complement pattern, start from the positive version of the number and follow three steps: write the positive value in 8 bits, flip every bit, then add 1.

Carrying out the three steps

  1. Write the positive value as 8 bits. Pad with leading zeros so the pattern is exactly 8 bits long.
  2. Flip every bit. Every 0 becomes a 1 and every 1 becomes a 0. Missing even one bit spoils the answer.
  3. Add 1 to the flipped pattern. Do the addition in binary, carrying where two 1s meet, and keep the answer to 8 bits.

The flip on its own gives a pattern that is one less than the value you need: the flipped 9 is 11110110, which is -10, not -9, so the add-one step must come after the flip, never before. A quick check on your answer: a negative number always starts with a 1 in the leftmost bit, while a positive number starts with 0. You only use these steps for negative values, because a positive number's pattern is already correct as it stands.

Worked example for -9

Step8-bit pattern
Positive 9 in binary00001001
Flip every bit11110110
Add 111110111

So -9 is stored as 11110111. A second run-through: positive 20 is 00010100, which flips to 11101011, and adding 1 gives 11101100 for -20.

Three rows of eight bit boxes show -9: positive 9 is 00001001, flipping every bit gives 11110110, and adding 1 gives 11110111. The leftmost bit is marked as the sign bit.

An 8-bit two's complement pattern that begins with a 1 in the most significant bit (the sign bit) stands for a negative number. To turn it into denary, use flip the bits and add one: change every 0 to a 1 and every 1 to a 0, add 1 to what you get, read that as the positive size, then put a minus sign in front.

The steps in order

  1. Check the leftmost bit is 1, so the value is negative.
  2. Flip all eight bits, not just some of them.
  3. Add 1 to the flipped pattern, working from the right-hand end.
  4. Read the result as an ordinary unsigned value.
  5. Write that value with a minus sign.

A worked example

Take 11011001.

  • Flip it: 00100110
  • Add 1: 00100111
  • Read it: 32 + 4 + 2 + 1 = 39
  • So 11011001 represents -39.

11011001 flipped to 00100110, then 1 added to give 00100111, read as 32 + 4 + 2 + 1 = 39, and the minus sign added to give -39.

Stopping at 39 gives a positive answer, which is wrong: the pattern stores a negative value, so the minus sign is part of the answer, not an optional extra. Nor is the sign bit a marker sitting outside the number. It is a real bit with a place value of -128, which is why any pattern starting with 1 is worth less than zero.

The same two steps work the other way round: to find the pattern for a negative denary value, write its positive size in binary, flip every bit and add 1. Converting each way is a mirror image of the other, so the method never changes.

There is a shortcut for turning a negative denary number into 8-bit two's complement. It skips the add-one step and produces exactly the same pattern as flip-every-bit-then-add-1, so both routes earn the marks.

The method

  1. Write the positive value of your number as 8 bits, padding with 0s on the left.
  2. Start at the right-hand side and move left until you reach the first 1.
  3. Copy every bit up to and including that 1 without changing it.
  4. Flip every bit to the left of it, turning each 1 into 0 and each 0 into 1.

Worked example: -26

Positive 26 is 00011010. Reading from the right, the first 1 is the second bit from the right, so you copy 10 as it stands. The six bits to its left, 000110, all flip to 111001. Joining the two parts gives 11100110, so -26 is 11100110. You can check it the long way: 26 flips to 11100101, and adding 1 gives the same answer.

Positive 26 is 00011010. Starting from the right, the first 1 is found and the bits 10 are copied unchanged, while the six bits to its left, 000110, flip to 111001, giving 11100110 for -26.

Another quick one: positive 9 is 00001001, so you copy the final 1, flip 0000100 to 1111011, and -9 is 11110111.

StepFlip all bits, then add 1Copy to the first 1, then flip
Start with 260001101000011010
Do the change11100101, then add 1keep 10, flip 000110 to 111001
Result for -261110011011100110

It works because adding 1 to the flipped pattern carries through the run of trailing 1s, turning them to 0s and the first 0 to their left into a 1. That restores the bits you copied — the trailing 0s and the first 1 — while everything to the left stays flipped. Only use it when converting a negative value: a positive number such as 26 keeps its plain binary pattern 00011010, with nothing flipped at all.

Also useful