Base-N · How-to

Two's Complement Walkthrough

How computers store negative integers — the invert-and-add-one rule, why it makes arithmetic painless, and an 8-bit example you can verify.

fx-991ES Web TeamUpdated 23 June 20267 min read

Two's complement is how nearly every computer represents negative whole numbers. Once you know the invert-and-add-one rule, reading and writing signed binary is straightforward — and a base-N calculator confirms it instantly.

On this page

  1. Why not just a minus sign?
  2. The invert-and-add-one rule
  3. 8-bit example: −5
  4. Why it works
  5. Sign bit & range
  6. FAQ

Why not just a minus sign?

Computers only store 0s and 1s, so the minus sign has to be encoded in the bits. The naive approach (a dedicated sign bit, "sign-magnitude") creates two zeros and needs special-case addition. Two's complement avoids both problems and lets one adder handle additions and subtractions.

The invert-and-add-one rule

  1. Write the positive value in binary at your chosen bit width.
  2. Invert every bit (the one's complement).
  3. Add 1.

8-bit example: −5

+5            = 00000101
invert bits   = 11111010   (one's complement)
add 1         = 11111011   ← −5 in two's complement

So in 8-bit, −5 = 11111011. As an unsigned value that pattern is 251, and 251 − 256 = −5, which is exactly the signed interpretation.

Why it works

Add 5 and −5 and watch the bits cancel:

  00000101   (5)
+ 11111011   (−5)
  --------
1 00000000   → drop the carry → 00000000 = 0  ✔

The carry out of the top bit is discarded, leaving zero — no special handling required. That's the whole point of the scheme.

Sign bit & range

The most significant bit acts as the sign: 0 for non-negative, 1 for negative. With 8 bits the signed range is −128 to +127. (Double the width to 16 bits and it becomes −32768 to +32767.)

On the calculator

In BASE-N mode, negative results are shown in two's complement form, and the NOT operator gives the one's complement — add 1 to reach two's complement. Build operands with decimal to binary conversion and operate using bitwise operations.

Frequently asked questions

How do I find the two's complement?

Write the value in binary, invert all bits, then add 1. For 5 (8-bit): 00000101 → 11111011 = −5.

Why is two's complement used?

Adding a number to its two's complement yields zero (carry dropped), so one adder handles add and subtract.

What's the range of an 8-bit signed integer?

−128 to +127, with the top bit as the sign.

Verify two's complement

Enter a negative number in BASE-N mode and view it in binary.

Open the two's complement calculator →