Digital Electronics · Lesson 4 of 33 · Numbers a computer understands

Negative numbers & 2's complement

Two's complement: storing −5 with no minus sign

🔒 Free with Google sign-in: loading…

Key ideas

  • A chip stores only 0s and 1s
  • No box for a '−' sign
  • The bits themselves must show the sign
  • Idea 1: leftmost bit = sign
  • +5 plus (−5) gives 2 ✗
  • Also two zeros: 0000 and 1000
  • Leftmost bit is worth −8
  • 1011 = −8 + 2 + 1 = −5
  • Leftmost bit 1 → negative
  • 4 bits = 16 patterns
  • 4 bits: −8 to +7
  • 8 bits: −128 to +127

Worked example

  • Step 1: flip every bit
  • Step 2: add 1
  • +5 = 0101 → −5 = 1011
  • Add normally, column by column
  • Drop the carry out of the last bit
  • +5 + (−5) = 0000 ✓
✗ Common mistakeThe most common mistake is forgetting to add one. One zero one zero is not minus five. It's minus six. Always flip, and then add one.
💡 Memory trickHere's the memory trick. Flip all, add one. And if the leftmost bit is one, the number is negative.
RecapComputers store negative numbers in two's complement. The leftmost bit has a negative weight. To negate a number, flip all the bits, then add one. And the range for four bits is minus eight to plus seven.
❓ Quick questionQuick question. In eight bit two's complement, what is one one one one, one one one one? The answer is in the next lesson.
See the answer in Lesson 5 →

Full lesson text

Read everything said in the video

Where you have seen itFirst, last lesson's question. One zero one zero is ten, which is A. One one zero zero is twelve, which is C. So the answer is A C.

Where you have seen itPicture a four bit counter showing zero zero zero one. Count down: zero zero zero zero. Count down once more, and it wraps around to one one one one. Just like an old car odometer rolling back from zero to nine nine nine nine. So one one one one must mean minus one.

The ideaHere's the problem. A chip can only store zeros and ones. There's no box for a minus sign. So we need a rule that uses the bits themselves.

The ideaThe first idea: use the leftmost bit as the sign. Zero for plus, one for minus. So minus five would be one one zero one. But add plus five and minus five, and the answer comes out as two, not zero. It even has two different zeros.

The ideaTwo's complement fixes this with one change. The leftmost bit is worth minus eight, instead of plus eight. Now one zero one one is minus eight, plus two, plus one. Minus five. And any number starting with one is negative.

Worked exampleTo make any negative number, use one rule. Five is zero one zero one. Flip every bit: one zero one zero. Then add one: one zero one one. That's minus five.

Worked exampleLet's check it. Add plus five and minus five, column by column, carrying ones as usual. The carry out of the last column falls off the end. What's left is zero zero zero zero. Exactly zero.

The ideaWith four bits there are sixteen patterns. Half are zero to plus seven. The other half are minus one to minus eight. With eight bits, the range is minus one twenty eight, to plus one twenty seven.

Common mistakeThe most common mistake is forgetting to add one. One zero one zero is not minus five. It's minus six. Always flip, and then add one.

Memory trickHere's the memory trick. Flip all, add one. And if the leftmost bit is one, the number is negative.

RecapLet's recap. Computers store negative numbers in two's complement. The leftmost bit has a negative weight. To negate a number, flip all the bits, then add one. And the range for four bits is minus eight to plus seven.

RecapQuick question. In eight bit two's complement, what is one one one one, one one one one? The answer is in the next lesson.

Ready to test yourself? Practise real digital electronics interview questions, with model answers.

Practice questions →

← All 33 lessons of the Digital Electronics course

Last updated