Two’s Complement Calculator

Enter a whole number and choose the number of bits.

Negative numbers are allowed within the range of the bit width.

Bit width

This result is an estimate only. Double-check important figures before relying on them.

How it is calculated

  • Positive numbers are written in ordinary binary, padded to the bit width
  • Negative numbers are stored as 2ⁿ + the number (the same as invert the bits, then add 1)
  • The range is −2ⁿ⁻¹ to 2ⁿ⁻¹ − 1

To see the number in other bases, use the number base converter.

Worked example

−5 in 8 bits:

  • 2⁸ − 5 = 251
  • Binary = 11111011, hex = FB

Why your number may differ

The width matters: the same bit pattern means different numbers at different widths. Some systems use other ways to store negatives, such as sign-magnitude.

Frequently asked questions

What is two’s complement?

The way computers store negative whole numbers. The top bit is the sign, and a negative number is stored as 2ⁿ minus its size.

How do I find −5 in 8 bits?

Write 5 as 00000101, flip every bit to get 11111010 and add 1, which gives 11111011.

What range does a bit width hold?

From −2ⁿ⁻¹ to 2ⁿ⁻¹ − 1. For 8 bits that is −128 to 127.