Skip to main content
SingaporeComputer ScienceSyllabus dot point

How do computers store negative whole numbers, and why is two's complement the standard scheme?

Represent signed integers using two's complement, convert to and from denary, and perform subtraction by addition, explaining range and overflow

A focused answer to the H2 Computing outcome on signed integers. Two's complement encoding, converting to and from denary, subtraction as addition, the representable range, and detecting signed overflow.

Generated by Claude Opus 4.88 min answer

Reviewed by: AI editorial process; not yet individually human-reviewed

Have a quick question? Jump to the Q&A page

Jump to a section
  1. What this dot point is asking
  2. The answer
  3. Examples in context
  4. Try this

What this dot point is asking

SEAB wants you to represent signed whole numbers in two's complement, convert both ways with denary, perform subtraction by adding a negation, and explain the representable range and how overflow is detected. The key insight is that two's complement lets one ordinary binary adder handle both positive and negative numbers, which is why every modern processor uses it.

The answer

What two's complement means

In an nn-bit two's complement number the most significant bit has a negative weight of 2n1-2^{n-1}, while all other bits keep their usual positive weights. For 8 bits:

128, 64, 32, 16, 8, 4, 2, 1-128,\ 64,\ 32,\ 16,\ 8,\ 4,\ 2,\ 1

So 110110112=128+64+16+8+2+1=3711011011_2 = -128 + 64 + 16 + 8 + 2 + 1 = -37. A leading 11 always means the number is negative; a leading 00 means it is non-negative.

Negating a number

To form the negative of any two's complement number: invert every bit, then add one. The same procedure undoes itself, so it converts +x+x to x-x and x-x back to +x+x.

+5  = 0000 0101
invert: 1111 1010
add 1:  1111 1011  = -5

Subtraction is addition

Because the negative is built into the encoding, aba - b is computed as a+(two’s complement of b)a + (\text{two's complement of } b). The processor has no separate subtractor: it negates and adds, discarding any carry out of the top bit.

The representable range

For nn bits the range is asymmetric:

2n1 to 2n11-2^{n-1}\ \text{to}\ 2^{n-1} - 1

For 8 bits that is 128-128 to +127+127. There is exactly one representation of zero (0000000000000000), which is a key advantage over sign-and-magnitude.

Detecting overflow

Signed overflow happens when adding two numbers of the same sign produces a result of the opposite sign. Equivalently, overflow occurred if the carry into the sign bit differs from the carry out of it. Adding numbers of opposite signs can never overflow.

Examples in context

Example 1. Temperature sensors. A microcontroller reading that can go below zero stores its value in two's complement, so a reading of 3-3 degrees is the byte 1111110111111101. The same arithmetic unit that adds positive readings handles the negative one without extra circuitry.

Example 2. The year-2038 problem. Many systems counted seconds since 1970 in a 32-bit signed integer. Two's complement caps that count at 23112^{31} - 1 seconds, which is reached in 2038; past it the value overflows to a large negative number, flipping the date to 1901. It is a direct consequence of the asymmetric signed range.

Try this

Q1. Represent 1-1 in 8-bit two's complement. [2 marks]

  • Cue. +1=00000001+1 = 00000001; invert to 1111111011111110, add 1 to get 1111111111111111, so 1-1 is all ones.

Q2. State the range of a 16-bit two's complement integer. [1 mark]

  • Cue. 215-2^{15} to 21512^{15} - 1, that is 32768-32768 to +32767+32767.

Q3. Does adding 0111111101111111 and 0000000100000001 (8-bit signed) overflow? Explain. [2 marks]

  • Cue. +127+1+127 + 1 gives 10000000=12810000000 = -128; two positives produced a negative, so yes, signed overflow occurred.

Exam-style practice questions

Practice questions written in the style of SEAB exam questions on this dot point, with worked answer explainers. The year tag is the paper they imitate, not the source.

Original5 marksUsing 8-bit two's complement: (a) represent 37-37 in binary; (b) state the range of integers an 8-bit two's complement number can hold; (c) explain why two's complement is preferred over a separate sign bit.
Show worked answer →

(a) First write +37+37 in 8-bit binary: 37=32+4+1=0010010137 = 32 + 4 + 1 = 00100101. To negate in two's complement, invert all bits then add 1.

+37:        0 0 1 0 0 1 0 1
invert:     1 1 0 1 1 0 1 0
add 1:      1 1 0 1 1 0 1 1

So 37=110110112-37 = 11011011_2.

(b) An 8-bit two's complement number holds 128-128 to +127+127, that is 27-2^7 to 2712^7 - 1.

(c) With a separate sign-and-magnitude scheme there are two representations of zero and addition needs special-case logic. Two's complement has a single zero and lets the same binary adder handle both positive and negative numbers, so subtraction becomes addition of the negation.

Markers reward the invert-and-add-one method, the correct asymmetric range, and the single-zero or unified-adder justification.

Original4 marksCompute 527052 - 70 using 8-bit two's complement arithmetic. Show the negation of 7070, the addition, the 8-bit result, and convert the result back to denary.
Show worked answer →

Subtraction is addition of the negation, so compute 52+(70)52 + (-70).

70=64+4+2=0100011070 = 64 + 4 + 2 = 01000110. Negate: invert to 1011100110111001, add 1 to get 70=10111010-70 = 10111010.

52=32+16+4=0011010052 = 32 + 16 + 4 = 00110100. Add:

00110100   (+52)
10111010   (-70)
---------
11101110

The result 11101110211101110_2 has its top bit set, so it is negative. Negate it to read the magnitude: invert to 0001000100010001, add 1 to get 00010010=1800010010 = 18. So the result is 18-18, which matches 5270=1852 - 70 = -18.

Markers reward negation by invert-and-add-one, the binary addition, recognising the negative result from the sign bit, and reading back the magnitude.

Related dot points