Boneyard Tools

Twos Complement Calculator

Convert any signed integer into its twos complement binary and hexadecimal form at the bit width you choose, or decode a bit pattern back into a signed value.

How to find twos complement

  1. Choose the bit width, such as 8, 16 or 32 bits.
  2. Enter the signed integer you want to represent.
  3. Read the twos complement binary, hex and unsigned value.

Examples

Encode -1 in 8 bits

Value -1, width 8 bits
Binary 11111111, hex 0xFF, unsigned 255

Frequently asked questions

What is twos complement?

Twos complement is the standard way computers store signed integers. A negative value is the bit pattern you get by adding 2 to the power of the bit width, so -1 in 8 bits is 11111111.

How do I calculate twos complement by hand?

Write the positive value in binary, flip every bit, then add 1. The result is the twos complement form, which this tool computes for you at any width.

Why is the range not symmetric?

An n-bit signed integer runs from minus 2 to the power n minus 1 up to 2 to the power n minus 1, minus 1. For 8 bits that is -128 to 127, so there is one more negative value than positive.

What does the unsigned value mean?

It is the same bit pattern read as a plain unsigned number. For -1 in 8 bits the pattern 11111111 equals 255 when treated as unsigned.

Can it decode binary back to a number?

Yes. Enter a bit pattern of the chosen width and the tool reads the top bit to decide the sign and returns the signed integer it represents.

Related tools