Two's Complement Converter
Computers store signed integers in two's complement: a non-negative number x is written in plain binary, while a negative number x is encoded as 2n − |x| in n bits — equivalently, flip every bit and add 1. The top bit is the sign bit (1 means negative), and an n-bit word represents the range −2n−1 .. 2n−1−1 (e.g. 8 bits spans −128..127). Enter a signed decimal (or a 0b/0x literal) and a bit width to see its two's-complement binary and hex encoding, the unsigned interpretation, the sign bit, the negated value, and whether it overflows the width. You can also paste an n-bit binary pattern to decode it back to a signed decimal. Everything runs locally in your browser.
Encode / decode
Result
Decode a binary pattern
The math. Two's complement is the standard signed-integer encoding because it lets the same hardware adder handle signed and unsigned values: a + b mod 2n gives the correct signed result whenever no overflow occurs. To encode a signed value v in n bits, compute e = v mod 2n (kept in 0 .. 2n−1 — for negative v this is 2n + v), then write e in binary padded to n digits. To decode an n-bit pattern, read it as unsigned e; if the sign bit (bit n−1) is set, the signed value is e − 2n, otherwise just e. Negation is (¬e) + 1 mod 2n — flip all bits and add one — which is why −x and x have complementary bit patterns and why there is one more negative than positive value (e.g. 8 bits can hold −128 but not +128). A value is in range when −2n−1 ≤ v ≤ 2n−1−1; anything outside overflows and cannot be represented without truncation. Uses BigInt so 64-bit widths are exact. Pairs with the Bitwise Calculator and the Number Base / Text-Binary converters. Everything runs locally — nothing leaves your browser.