BeginnerTopic 36 of 104Electronics & Embedded

Two's complement

Standard way to represent signed integers in binary.

In depth

Negative numbers are represented by inverting all bits and adding 1. An n-bit range is -2ⁿ⁻¹ to 2ⁿ⁻¹-1. Addition works the same for signed and unsigned, with overflow detection by sign bits. Sign extension preserves value when widening.

Key points

  • MSB indicates sign
  • Single zero representation
  • Subtraction becomes addition
Example

8-bit -5 = 11111011.

Why it matters

Two's complement lets a processor perform signed arithmetic with the same adder as unsigned arithmetic, so it is used in almost every processor.

Where this is used

  • Checking the range of an 8-bit signed sensor value.
  • Understanding why an overflow flips a positive result to negative.
  • Converting a negative temperature reading stored as a byte.

Frequently asked questions

What is Two's complement?

Standard way to represent signed integers in binary.

Why is it important to understand two's complement?

Two's complement lets a processor perform signed arithmetic with the same adder as unsigned arithmetic, so it is used in almost every processor.

How do I make a number negative in two's complement?

Invert all bits and add one, so minus five in 8-bit is 11111011.

What range does an 8-bit signed value cover?

From minus 128 to plus 127.

How is Two's complement used in practice?

Typical applications include checking the range of an 8-bit signed sensor value, understanding why an overflow flips a positive result to negative and converting a negative temperature reading stored as a byte.

What should I learn before Two's complement?

Study "Number conversions" first (topic 35 of 104 in Electronics & Embedded). It covers the groundwork this topic builds on.

What are the key points of Two's complement?

MSB indicates sign. Single zero representation. Subtraction becomes addition.

Can you give an example of Two's complement?

8-bit -5 = 11111011.

What comes after Two's complement?

The next topic is "Logic gates", which builds directly on this one.

How difficult is Two's complement?

It is classed as Beginner in Electronics & Embedded (topic 36 of 104). It is an entry-level topic. It relies only on basic school mathematics and the ideas introduced earlier in this discipline.

Learning path

Want to practise? Open the interactive course for quick checks, quizzes, simulations and progress tracking.

Related topics