Skip to content
ZeroServer.tools

Two's Complement Converter

Convert between decimal integers and two's complement binary — 8, 16, 32, or 64-bit.

Binary (two's complement)
11010110
Hexadecimal
0xD6
Bit width
8-bit
11010110← sign bit

How two's complement works

Two's complement is the standard way computers represent signed integers. For a positive number, it's the same as unsigned binary. For a negative number: invert all bits and add 1. The most significant bit (MSB) is the sign bit — 0 = positive, 1 = negative.

To work with binary numbers generally, see Binary to Decimal and Decimal to Binary. For bitwise operations, try Bitwise Calculator.

Built and maintained by Meet Shah · Last updated

What this tool is used for

  • Reading a negative value out of a register dump or a protocol field.
  • Checking what a signed 8-bit value wraps to at the boundary.
  • Confirming your own sign-extension logic against a known width.
  • Understanding why an integer overflowed to a negative number in a bug report.
  • Converting a decimal offset into the bit pattern a low-level format expects.

Frequently Asked Questions

Why is two's complement used instead of a sign bit?
Because addition then works unchanged for negative numbers — no special case, no separate subtract circuit. It also gives exactly one zero, where a sign-and-magnitude representation has both +0 and −0 and has to decide whether they are equal.
How do I negate a number by hand?
Invert every bit and add one. 5 in 8-bit is 00000101; inverted it is 11111010; plus one is 11111011, which is −5. Doing it twice returns you to where you started, which is the property that makes the representation work.
Why is the negative range one larger?
8-bit signed runs from −128 to +127, not −127. Zero takes one of the positive slots, so there is one more pattern available below zero. That asymmetry is real: negating −128 in 8 bits overflows back to −128, and the same trap exists at every width.
Is the arithmetic exact at 64 bits?
Yes — everything here runs on BigInt. A double cannot do this: it is exact only to 2⁵³, so a 64-bit conversion done in ordinary JavaScript numbers prints int64 maximum as 9223372036854776000 and turns −1 into a 65-bit string.
How does sign extension work?
Widening a negative number copies the sign bit leftwards: −5 as 11111011 in 8 bits becomes 1111111111111011 in 16. Copying zeros instead — a zero extension — would turn −5 into 251, which is the classic bug when a signed byte is read as unsigned.

Common errors and gotchas

  • Converting without choosing a width first, which makes the answer undefined for any negative value.
  • Sign-extending when you meant to zero-extend, which turns a small positive into a large negative.
  • Confusing the sign bit with a flag bit in a field that packs both.
  • Assuming the range is symmetric, when the negative side reaches one further than the positive.
  • Reading a hex value as unsigned by default, so `FF` is 255 in one reading and -1 in another.

Related Converters tools

Private & free — this tool runs entirely in your browser.

IndieKitShip your Next.js startup in days.affiliate