Two's Complement Calculator

Convert a signed decimal value into fixed-width two's complement binary, or decode a two's complement bit pattern back into decimal. Exact at every supported width, including 64-bit, using BigInt arithmetic.

Conversion inputs

Plain integer only, optionally signed with + or -. No decimals or exponents.

Valid range at 8-bit: -128 to 127

What Is Two's Complement?

Two's complement is the standard way computers represent signed (positive and negative) integers in a fixed number of bits. Positive numbers are written as ordinary binary; negative numbers are represented as the value's complement modulo 2N, where N is the bit width you choose.

Because bit width is fixed in advance, the same N bits can represent a range of both positive and negative integers: from -2(N-1) up to 2(N-1) - 1. Choosing 8-bit, 16-bit, 32-bit, or 64-bit changes that range, so the same decimal value can produce a different bit pattern depending on width.

Use Decimal → Two's Complement above to convert a signed decimal number into its binary form at a chosen bit width, or Two's Complement → Decimal to interpret an existing bit pattern as a signed number. If you only need an ordinary unsigned decimal-to-binary conversion — no sign bit, no fixed width — the Decimal to Binary Converter is the more direct tool; for a plain hexadecimal value's unsigned base-10 equivalent, use the Hex to Decimal Converter instead.

For the full explanation behind these conversions — why bit width changes the result, how the range works, and how two's complement compares to one's complement — see Two's Complement Explained.

How Two's Complement Is Calculated

For a negative value, at a fixed bit width N:

  1. Write the absolute value in N-bit binary.
  2. Invert every bit (one's complement).
  3. Add 1 to the result.

Worked example: -5 in 8-bit two's complement

Decimal: -5

Step 1: Write +5 in 8-bit binary
00000101

Step 2: Invert all bits (one's complement)
11111010

Step 3: Add 1
  11111010
+        1
----------
  11111011

Result: -5 in 8-bit two's complement = 11111011

The reverse works the same way: given a bit pattern whose most significant bit (MSB) is 1, invert the bits and add 1 to find the magnitude, then apply a negative sign. The MSB is the sign bit: 0 means positive, 1 means negative. For arithmetic on unsigned binary values, see the Binary Calculator; for AND/OR/XOR/shift operations, see Bitwise Operations.

Signed Range by Bit Width

For N-bit two's complement, the valid signed range is -2(N-1) to 2(N-1) - 1:

Bit WidthMinimumMaximumTotal 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

64-bit values exceed what JavaScript's Number type can represent exactly, so this calculator computes them with BigInt rather than Number or 32-bit bitwise operators.

Why Computers Use Two's Complement

Single addition circuit

Subtraction becomes addition of a negative number, so hardware needs only one arithmetic circuit.

One representation of zero

Unlike one's complement, which has both +0 and -0, two's complement has a single zero bit pattern.

No special-cased sign logic

Addition and subtraction work the same way regardless of the operands' signs.

Universal in modern CPUs

Virtually all processors use two's complement for signed integer types.

8-bit Two's Complement Examples

Decimal8-bit Two's Complement
000000000
100000001
200000010
500000101
12701111111
-111111111
-211111110
-511111011
-12810000000

128 and -129 are both invalid in 8-bit signed two's complement, since the valid range is -128 to 127.

Frequently Asked Questions

How do I convert a negative decimal number to two's complement?

Choose a bit width, write the absolute value in binary, flip all the bits, then add 1. For example, -5 in 8-bit two's complement is 11111011. The "Decimal → Two's Complement" mode above does this directly.

How do I read a two's complement binary value back into decimal?

Check the leftmost bit (MSB). If it is 0, read the value as ordinary unsigned binary. If it is 1, the number is negative — flip all the bits, add 1, and negate the result. The "Two's Complement → Decimal" mode does this automatically.

Why is the range asymmetric, e.g. -128 to 127 for 8-bit?

Zero itself uses one positive bit pattern (00000000), leaving one fewer pattern available for positive numbers than negative ones. That is why the minimum is -2^(n-1) and the maximum is 2^(n-1) - 1.

What happens if I enter a binary value shorter than the selected bit width?

It is padded with leading zeros to match the selected width, which preserves its value as a positive number. Padding never changes a value’s sign, so a negative number must be entered at its full bit width, including its leading 1s.

What's the difference between one's complement and two's complement?

One's complement only flips the bits. Two's complement flips the bits and adds 1. Two's complement is what real hardware uses because it produces a single representation of zero and lets addition and subtraction share one circuit.

Can this calculator handle 64-bit values without losing precision?

Yes. All calculations use exact BigInt arithmetic rather than JavaScript's 32-bit bitwise operators or the floating-point Number type, so 64-bit boundary values like -9223372036854775808 and 9223372036854775807 convert exactly.

Related Tools

Decimal to Binary Converter

Ordinary unsigned decimal-to-binary conversion, no sign bit or fixed width.

Binary to Decimal Converter

Convert plain unsigned binary to decimal.

Binary Calculator

Add, subtract, multiply, and divide unsigned binary values.

Bitwise Operations

AND, OR, XOR, NOT, and shift operations on binary values.