Two's Complement Calculator

Convert between signed decimal values and their binary representation.

What the Two's Complement Calculator does

Two’s complement represents negative numbers by inverting the bits of the magnitude and adding one. The top bit then acts as a sign flag, and ordinary binary addition gives correct results for both signs — which is why virtually every processor uses it.

Formula

  • Negative value = ~magnitude + 1
  • Signed value = unsigned − 2ⁿ when the sign bit is set
  • Signed range = −2ⁿ⁻¹ to 2ⁿ⁻¹ − 1
  • Unsigned range = 0 to 2ⁿ − 1

Inputs explained

InputUnitRequiredNotes
Start fromone of 2 optionsYes
Decimal valuetextIn some modesShown Start from is A decimal value.
Bit patterntextIn some modesShown Start from is A binary or hex bit pattern.
Pattern is inone of 2 optionsIn some modesShown Start from is A binary or hex bit pattern.
Bit widthone of 4 optionsYes

How to use it

  1. Choose Start from and Bit width.
  2. Fill in the remaining inputs the form shows for your choice.
  3. Select Calculate.

Worked example

Representing −5 in 8 bits.

Value
−5
Bit width
8-bit

5 is 00000101. Inverting gives 11111010, and adding 1 gives 11111011 — 0xFB, which reads as 251 unsigned.

Frequently asked questions

Why is the signed range asymmetric?

Zero takes one of the 2ⁿ patterns from the positive side, leaving one fewer positive value than negative. An 8-bit signed integer spans −128 to 127.

What happens on overflow?

The value wraps around. Adding 1 to 127 in 8-bit signed gives −128, because the bit pattern rolls from 01111111 to 10000000.

Related calculators