Two's Complement Calculator

Encode a signed integer as a two's complement bit pattern, or read a binary or hex pattern back as a signed number, with ranges and sign extension.

Convert
Automatic picks the smallest of 8, 16, 32 or 64 bits for a decimal number, or the number of digits you typed for a bit pattern.
Two’s complement
1101 0110
Hexadecimal
0xD6
Signed value
−42
Same bits as unsigned
214
One’s complement
1101 0101inverted bits, without the +1
Sign-magnitude
1010 1010sign bit + magnitude
8-bit signed range
−128 to 127
−42 in 8-bit two’s complement1101 01100xD6

Show the work

  1. Write the magnitude 42 in 8-bit binary: 0010 1010
  2. Invert every bit (one’s complement): 1101 0101
  3. Add 1: 1101 0110
  4. Shortcut: 28 − 42 = 256 − 42 = 214 = 0xD6
Sign extension: the same value in wider registers
WidthBinaryHex
8-bit1101 01100xD6
16-bit1111 1111 1101 01100xFFD6
32-bit1111 1111 1111 1111 1111 1111 1101 01100xFFFFFFD6
64-bit1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1101 01100xFFFFFFFFFFFFFFD6
Signed ranges by width
WidthMinimumMaximumDistinct values
4-bit−8716
8-bit−128127256
16-bit−32,76832,76765,536
32-bit−2,147,483,6482,147,483,6474,294,967,296
64-bit−9,223,372,036,854,775,8089,223,372,036,854,775,80718,446,744,073,709,551,616

Computers store negative integers in two’s complement, a scheme where the leftmost bit carries a negative weight. It lets the same adder circuit handle positive and negative numbers, gives zero a single representation and makes overflow behave predictably. This calculator converts a signed decimal into its two’s complement bit pattern at any width from 4 to 64 bits, or reads a binary or hex pattern back as a signed value, showing the invert-and-add-one steps either way.

How to use the two’s complement calculator

  1. Choose Decimal → two’s complement to encode a number, or Bits → decimal to decode a pattern.
  2. Pick the bit width, or leave it on Automatic: for decimals that picks the smallest of 8, 16, 32 or 64 bits that fits; for patterns it uses the number of digits you typed.
  3. Enter a decimal integer (for example −42) or a bit pattern in binary or hex (for example 1101 0110 or D6).
  4. Read the binary and hex pattern, the signed and unsigned readings, the one’s complement and sign-magnitude forms, and the range of the chosen width. A sign-extension table shows the same value in wider registers.

Two’s complement formulas

For an n-bit pattern with bits bn−1 … b0, the leftmost bit has a negative weight:

value = −bn−1·2n−1 + bn−2·2n−2 + … + b0

To encode a negative number −x:

pattern = 2n − x  =  (NOT x) + 1

The range is −2n−1 to 2n−1 − 1.

Worked example

Encode −42 in 8 bits.

Magnitude: 42 = 0010 1010.

Invert every bit: 1101 0101 (this is the one's complement).

Add 1: 1101 0110, which is 0xD6.

Check with the shortcut: 2⁸ − 42 = 256 − 42 = 214 = 1101 0110. ✓

Check with place values: −128 + 64 + 16 + 4 + 2 = −42. ✓

Decoding FFFE as a 16-bit value: the sign bit is 1, inverting gives 0000 0000 0000 0001, adding 1 gives 2, so the value is −2. Read as unsigned, the same bits are 65,534.

Signed ranges

Width Minimum Maximum Typical type
8-bit −128 127 int8, signed char
16-bit −32,768 32,767 int16, short
32-bit −2,147,483,648 2,147,483,647 int32, int
64-bit −9,223,372,036,854,775,808 9,223,372,036,854,775,807 int64, long

Why computers use it

  • One adder for everything. Adding 0000 0101 (5) and 1111 1101 (−3) in 8 bits gives 1 0000 0010; dropping the carry out of the top leaves 0000 0010 = 2. No special subtraction hardware is needed.
  • One zero. Sign-magnitude and one’s complement both have a +0 and a −0; two’s complement has only 0000 0000.
  • Sign extension is easy. To widen a value, copy the sign bit into the new high bits: −42 is D6 in 8 bits, FFD6 in 16 bits and FFFFFFD6 in 32 bits.

Overflow

Adding two numbers with the same sign can produce a result with the opposite sign when the true answer does not fit. In 8 bits, 100 + 50 = 150 exceeds 127 and wraps to 1001 0110, which reads as −106. Processors detect this with an overflow flag; languages handle it differently (wrapping, trapping or undefined behavior), a frequent source of bugs.

For AND, OR, XOR and arithmetic shifts on signed values, use the bitwise calculator. For plain base-2 arithmetic, try the binary calculator, and to convert between bases without a fixed width, the number base converter.

Frequently asked questions

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

Write the magnitude in binary at the chosen width, invert every bit, then add 1. For −42 in 8 bits: 42 = 00101010, inverted 11010101, plus 1 = 11010110. Equivalently, compute 2^n − 42 = 256 − 42 = 214 and write that in binary.

How do I convert two's complement back to decimal?

If the leftmost bit is 0, read the number as ordinary binary. If it is 1, the number is negative: invert the bits, add 1 and put a minus sign in front. 11010110 inverts to 00101001, plus 1 is 00101010 = 42, so the value is −42.

What is the range of an 8-bit signed integer?

−128 to 127. In general an n-bit two's complement integer runs from −2^(n−1) to 2^(n−1) − 1, so 16 bits hold −32,768 to 32,767 and 32 bits hold about ±2.1 billion.

Why is there one more negative number than positive?

Zero takes one of the patterns with a 0 sign bit, leaving 2^(n−1) − 1 positive values but 2^(n−1) negative ones. The extra one, such as −128 in 8 bits (10000000), has no positive counterpart, so negating it overflows back to itself.

Last reviewed October 2026 by the CalcFluent editorial team. How we check our calculators.