Computer Science · Data representation

How do I write a negative number in two's complement without getting confused?

IGCSE and GCSE 2 min read Worked answer

There is a two-step method that always works, and most of the confusion comes from students half-remembering a third step that does not exist.

The method

To write -45 as an 8-bit two's complement number:

Step 1. Write the positive number in binary.

45 in 8 bits is 00101101. (32 + 8 + 4 + 1 = 45.)

Step 2. Flip every bit, then add one.

Flip: 11010010 Add 1: 11010011

That is the answer. -45 is 11010011.

There is no step three. You do not flip again, you do not adjust the sign bit separately, and you do not do anything different if the number is odd.

Checking it without redoing the work

The fastest check is to add the two representations together. A number and its two's complement negative must sum to zero in eight bits:

  00101101   (45)
+ 11010011   (-45)
-----------
 100000000

The ninth bit falls off the end because we only have eight, leaving 00000000. That is zero, so the answer is right. This check takes about fifteen seconds and catches almost every mistake.

The three places it goes wrong

Forgetting to add one. Flipping the bits alone gives you one's complement, which is a different system that exams do not use. 11010010 is not -45, it is -46 read as two's complement. If your answer is consistently one out, this is why.

Running out of bits. In 8 bits, two's complement covers -128 to +127. Ask for -130 and there is no answer; the question is invalid. But +130 is also unrepresentable as a signed 8-bit number, which trips people up because 130 is clearly writable as 10000010 in plain binary. In two's complement that bit pattern means -126. The number of bits is part of the question, not a detail.

Reading a negative back the wrong way. Going from 11010011 to -45 uses the same operation: flip and add one gives 00101101 = 45, so the original was -45. Students often expect the reverse direction to need a different method. It does not. Two's complement is its own inverse.

Why the leading bit is not really a sign bit

You will be told that a leading 1 means negative, and that is true and useful. But describing it as "the sign bit" causes a specific misunderstanding: students start treating it as a flag stuck on the front of a positive number, and then try to read the remaining seven bits as a magnitude.

11010011 has 1010011 = 83 in its lower seven bits, and the answer is not -83. The leading bit carries a place value like every other bit, and in two's complement that place value is negative: -128. So the number is -128 + 64 + 16 + 2 + 1 = -45. Same answer, different route, and this route explains why the range is lopsided at -128 to +127 rather than symmetric.

What this is worth

Data representation questions are reliable marks and they recur every series. The arithmetic is trivial once the method is automatic, and the method takes about twenty minutes to make automatic. It is one of the highest-return twenty minutes available in the subject.

Practise it by writing five negatives, checking each with the addition test, and then converting each back. If all five round-trip correctly you are done with this topic.

Working from a past paper? Mark your attempt against the published mark scheme before reading an answer like this one. Finding out where you lost the marks is worth more than seeing a correct solution, because the correct solution rarely tells you what you did instead.

Related questions

Ordered by how close they are to this one: same topic first, then the same subject.

Why does my trace table always go wrong on the last iteration?

Because you are almost certainly checking the condition at the wrong moment, and the last row is the only place that difference shows up.

Algorithms and tracing 3 min

I wrote working Python and got half marks. Why?

Because the paper asked for pseudocode and marks the structure, not whether the code would run. A correct Python answer can miss several structural marks while…

Programming and pseudocode 2 min

I keep mixing up xylem and phloem in the exam. Is there a way to stop doing that?

Yes, and it is not a mnemonic. Learn one fact about each and derive the rest, because the two tissues differ in almost every way once you have the starting point.

Transport in plants 2 min

Why do we bother with depreciation if no money actually leaves the business?

You are right that no cash moves. That is exactly why the concept exists, and seeing the reason makes the whole topic easier to hold onto.

Depreciation and the matching concept 2 min

Mean, median or mode: how do I justify which average a question wants?

Look at the distribution, not the data type. The decision turns almost entirely on whether there are extreme values, and a question giving you a skewed data set is…

Measures of central tendency 2 min

Why does adding a second lamp in parallel not make both lamps dimmer?

Because in parallel each lamp gets the full supply voltage, regardless of how many others are connected. Adding another branch does not take anything away from the…

Electric circuits 2 min