UTILS.
100% in-browser
🔢

Two's Complement Converter

Convert signed integers to/from two's-complement binary and hex at 4, 8, 16, 32 or 64-bit width, with one's complement and unsigned interpretation.

Enter a number or bit pattern above.

About this tool

The Two's Complement Converter encodes a signed integer into its two's-complement binary and hexadecimal representation at a bit width you choose (4, 8, 16, 32 or 64 bits), and decodes a binary or hex pattern back into the signed value it represents. It uses BigInt throughout, so 64-bit values are handled exactly with no precision loss.

For a width of N bits the signed range is −2^(N−1) to 2^(N−1)−1. To encode a decimal d: if d is non-negative the pattern is simply d; if d is negative the pattern is 2^N + d (equivalently, invert all bits of |d| and add 1). The tool outputs the N-bit zero-padded binary, the N/4-digit hex, the one's complement (bitwise NOT), and the unsigned interpretation of the same bits, and it flags an overflow error when a value does not fit the selected width.

To decode, paste a binary or hex pattern and the tool reads its top bit: if the most significant bit is set the value is pattern − 2^N (negative), otherwise it is the pattern itself. It always shows both the signed and unsigned readings side by side, which is exactly the ambiguity two's complement resolves at the hardware level. All computation is local to your browser.

Frequently asked questions

What is the range for each bit width?
A width of N bits represents signed values from −2^(N−1) to 2^(N−1)−1. So 8-bit spans −128 to 127, 16-bit −32768 to 32767, and 32-bit about ±2.1 billion. Values outside the range trigger an overflow warning.
How is a negative number encoded?
Take the magnitude, invert every bit (one's complement), and add 1. Equivalently the pattern equals 2^N plus the negative number. For example −1 in 8 bits is 11111111, and −42 is 11010110.
Why show the unsigned value too?
The same bit pattern has two readings: signed (two's complement) and unsigned. Showing both makes it clear that, for instance, the 8-bit pattern 11111111 is −1 signed but 255 unsigned — the interpretation depends on how the hardware treats it.
Can it handle 64-bit values exactly?
Yes. The converter uses arbitrary-precision BigInt arithmetic, so 64-bit patterns and their signed values are computed exactly without the rounding that ordinary JavaScript numbers would introduce beyond 2^53.

More tools