Skip to content
FiftyCalc Free calculators for all 50 states

Two's Complement Calculator

Test cases replayed : 4 of 4 match · Methodology · No outside source listed

Enter a signed whole number and a bit width to see how a computer stores it in two's complement: the bit pattern and the same bits read as an unsigned number.

Result

Sample figures

Two's complement bit pattern (leading zeros not shown)—

Smallest value for this width −2ⁿ⁻¹ —

  • Largest value for this width 2ⁿ⁻¹ − 1—
  • Same bits read as unsigned (x, or 2ⁿ + x when x is negative)—

Estimate for planning only, not tax, legal, financial or medical advice. This calculator uses the method explained on this page.

Two's Complement Calculator

Signed whole number (decimal): enter a number. Prefilled example: -5.

Bit width

Bit width: choose 4 bits, 8 bits, 12 bits or 16 bits. Prefilled example: 8 bits.

How to use this calculator

Fill in the fields in this order; each step takes you to its field.

  1. Signed whole number (decimal): enter a number.
  2. Bit width: choose 4 bits, 8 bits, 12 bits or 16 bits.
  3. Read the result: Two's complement bit pattern (leading zeros not shown); the panel also shows Smallest value for this width −2ⁿ⁻¹, Largest value for this width 2ⁿ⁻¹ − 1 and Same bits read as unsigned (x, or 2ⁿ + x when x is negative).

How this calculator works

In n-bit two's complement, a non-negative number is written in plain binary and a negative number x is stored as the binary form of 2ⁿ + x. The leftmost bit is then 1 for every negative number, and the representable range is −2ⁿ⁻¹ to 2ⁿ⁻¹ − 1 (−128 to 127 for 8 bits).

The same pattern is obtained by hand by writing |x| in binary, flipping every bit (the ones' complement) and adding 1. A number outside the range for the chosen width cannot be stored and is shown as a dash; for positive numbers, the bit pattern omits the leading zeros up to the chosen width.

Worked example

Signed whole number (decimal)-5
Bit width8 bits
Smallest value for this width −2ⁿ⁻¹-128
Largest value for this width 2ⁿ⁻¹ − 1127
Same bits read as unsigned (x, or 2ⁿ + x when x is negative)251
Two's complement bit pattern (leading zeros not shown)11111011

Frequently asked questions

What is −5 in 8-bit two's complement?

11111011, which is 251 read as an unsigned byte (256 − 5).

What is −1 in 16-bit two's complement?

Sixteen ones, 1111111111111111, or 65,535 read as unsigned.

Can 200 be stored in 8-bit two's complement?

No. The 8-bit range is −128 to 127, so 200 needs at least 9 bits.

Related calculators