Two's complement calculator

Type a negative or positive whole number, or paste a binary or hex bit pattern, and choose the word size. The calculator shows the two's complement bits, the hex value, the signed and unsigned readings and, for negative numbers, the steps from the absolute value.

Decimal like -42, binary like 11010110 or hex like D6 (0b and 0x prefixes are fine).
Two's complement (binary)1101 0110
HexD6
Signed value
-42
Unsigned value
214
Sign bit
1 (negative)
Step 1: absolute value in binary
0010 1010
Step 2: invert every bit
1101 0101
Step 3: add 1
1101 0110
Signed range for this width
-128 … 127

Runs in your browser: nothing you enter is sent anywhere.

How to use it

  1. Type the value. Choose Decimal for a number such as -42, or Binary / Hex to decode an existing bit pattern.
  2. Choose the width: 8, 16, 32 or 64 bits. A short binary or hex pattern is padded with zeros on the left.
  3. Read the two’s complement bits (grouped by four), the hex value, and the pattern read both as signed and as unsigned. For negative numbers the three textbook steps are listed.

How two’s complement works

With n bits a negative number x is stored as 2ⁿ + x. In practice that is the same as taking |x| in binary, inverting every bit and adding 1. To go back, look at the top (sign) bit: 0 means the value is the binary number itself; 1 means subtract 2ⁿ from the unsigned value.

Width Signed range −1 is stored as
8 bits −128 … 127 FF
16 bits −32,768 … 32,767 FFFF
32 bits −2,147,483,648 … 2,147,483,647 FFFFFFFF

Worked example

Find −42 as an 8-bit value.

  • Step 1: 42 in binary is 0010 1010.
  • Step 2: inverted, 1101 0101.
  • Step 3: plus 1, 1101 0110, which is D6 in hex.

Read unsigned, 1101 0110 is 214, and 214 − 256 = −42, so the pattern really means −42. The calculator also shows the range for 8 bits: -128 … 127.

Common mistakes

  • Forgetting the width. −1 is FF in 8 bits but FFFFFFFF in 32 bits. The same bits mean different numbers at different widths: 1111 1111 is −1 as a byte but 255 as the low byte of a 16-bit value.
  • Adding 1 before inverting. The order is invert, then add 1. The other way round gives the wrong answer.
  • Expecting −128 to have a positive twin. The most negative value has no positive counterpart in the same width: inverting 1000 0000 and adding 1 gives 1000 0000 again.

Frequently asked questions

How do I find the two's complement of a negative number?

Write the absolute value in binary at the chosen width, flip every bit, then add 1. For −42 in 8 bits: 42 is 0010 1010, flipped it is 1101 0101, plus 1 gives 1101 0110, which is D6 in hex.

How do I read a two's complement number?

If the top bit is 0, the number is the plain binary value. If it is 1, the value is negative: subtract 2 to the power of the width. 1101 0110 is 214 unsigned, and 214 − 256 = −42.

What range fits in 8, 16, 32 and 64 bits?

From −2^(n−1) to 2^(n−1) − 1: −128 to 127 for 8 bits, −32,768 to 32,767 for 16 bits, about ±2.1 billion for 32 bits and about ±9.2 × 10^18 for 64 bits. The calculator shows the exact range for the width you pick.

What happens if I type 200 with 8 bits?

200 does not fit in a signed byte, but it fits as an unsigned one, so the calculator treats it as the bit pattern 1100 1000. Read as signed, that pattern is −56. Numbers below −128 or above 255 are rejected.

Why do computers use two's complement?

Addition and subtraction work the same for signed and unsigned numbers, there is only one zero, and the sign is simply the top bit. That is why practically every CPU stores signed integers this way.

More in Developer

All tools in this category: Developer ·Updated November 7, 2026

Privacy choices

Google Analytics shows us which tools are used and whether they work. It may set cookies. Your choice is kept in this browser.