Home›Study Resources›Computer Science›
How does two’s complement work?
Computer Science
Higher

How does two’s complement work?

Two’s complement stores positive and negative whole numbers in binary. The left-hand bit has a negative place value, so for 8 bits it is −128. To make a number negative, invert every bit of the positive value, then add 1. With n bits the range is −2ⁿ⁻¹ to 2ⁿ⁻¹ − 1. Example: −45 in 8 bits. 45 = 00101101, invert to 11010010, add 1. Answer: 11010011.

Quick answer: Two’s complement is a method of representing positive and negative integers in binary, where the left-hand bit has a negative place value. This page covers Higher Computing Science, SQA (C816 76), Computer systems: data representation.

Key rule

  • Range for n bits: −2n−1 to 2n−1 − 1. For 8 bits that is −128 to 127.
  • Positive to negative: write the positive number in n bits, invert every bit, then add 1.
  • Binary to denary: the left-hand bit is worth −2n−1. Add the other place values as normal.
  • If the left-hand bit is 1, the number is negative.

Extra example

Convert 10110100 from 8-bit two’s complement to denary.

  1. The left-hand bit is 1, worth −128.
  2. The other 1s are worth 32, 16 and 4, which add to 52.
  3. Total: −128 + 52 = −76.
  4. Check by negating: invert 10110100 to 01001011, add 1 to get 01001100, which is 76.

Answer: 10110100 is −76 in denary.

Want one-to-one help? Find an online Computer Science tutor with ExpertTutor.

Reviewed by

Want one-to-one support?

One-to-one online tuition can help you build confidence in your subject. Find a tutor who teaches your course.

Find a Tutor

Learn face to face in Glasgow

Prefer in-person lessons? Visit the ExpertTutor Glasgow Southside centre.

See the centre