Convert signed decimal integers to two's complement binary and back. See the full step-by-step conversion with a live bit visualization for 8, 16, 32, and 64-bit widths.
Two's complement is the most widely used method for representing signed integers in binary. Every modern CPU — from your smartphone to a supercomputer — uses two's complement internally for integer arithmetic. Understanding it is fundamental to low-level programming, embedded systems, and computer architecture.
In an n-bit two's complement system the most significant bit (MSB) carries a negative weight of −2n−1, while all other bits carry their normal positive powers of 2. This single design choice means that addition and subtraction circuits work identically for both positive and negative numbers, which is why hardware designers love it.
Key properties that make two's complement special:
−2n−1 to +2n−1 − 1 — one more negative number than positive.−. Values outside the selected bit-width range will show a range error.0s and 1s. The leftmost bit is treated as the sign bit. Leading zeros matter — 00001101 (8-bit) decodes as +13, while 11110011 decodes as −13.Converting a negative decimal to two's complement (Decimal → Binary):
Decoding two's complement binary back to decimal (Binary → Decimal):
0: the number is non-negative. Read the binary value directly as an unsigned integer.1: the number is negative. Apply the same procedure in reverse — invert all bits, add 1, read the magnitude, then negate.Mathematical shortcut: The signed value of any n-bit two's complement string can be computed directly as:
Implementation note: In JavaScript, bitwise operators work internally on signed 32-bit integers. This tool handles all widths (8, 16, 32, 64) using pure arithmetic — adding 2n to negative values to get the unsigned representation, and subtracting 2n from values with a set MSB to decode them.