Two's Complement Calculator

Decimal to two's complement binary

Enter a signed integer and a bit width. Negative values wrap using the standard 2bitWidth + value identity.

Two's complement binary to decimal

Enter exactly as many 0s and 1s as the chosen bit width.

How it works

Two's complement is how signed integers are stored in binary: non-negative values are their plain binary form, and a negative value v at width n is stored as 2n + v. The top bit works out to be 1 for every negative value and 0 for every non-negative one, which is why it is often called the sign bit. All arithmetic here uses BigInt, so 64-bit values are exact — a plain Number starts losing precision above 253, well inside the 64-bit range.