Two's Complement Converter (Any Bit Width, Binary & Hex)

Convert a signed integer to two's complement binary and hex at 8, 16 or 32 bits — or any width you choose — and decode a bit pattern back to signed decimal.

Working
00000101  Zero or positive: the pattern is the plain binary, padded with zeros.
00000101 Zero or positive: the pattern is the plain binary, padded with zeros.
Every 8-bit pattern

What two's complement is

Two's complement is the standard way computers store signed integers. A positive number looks like its plain binary value, while a negative number is stored by inverting the bits of its magnitude and adding one. This gives a single, unambiguous representation of zero and lets the CPU add and subtract signed numbers with the same circuitry it uses for unsigned ones. The most significant bit acts as the sign: 0 for non-negative, 1 for negative.

Using this converter

Pick a bit width — 8, 16 or 32 bits, another preset, or any width you type — then type a signed decimal to see its two's complement binary and hexadecimal, or type a binary pattern to decode it back to a signed decimal. Each field updates the others instantly. The tool enforces the valid range for the chosen width — for example an 8-bit value must be between -128 and 127 — and shows a clear message when a value falls outside it. The hex output is the unsigned bit pattern, which is why -1 shows as 0xFF at 8 bits and 0xFFFFFFFF at 32 bits. A checkbox above the boxes spaces the binary and hex digits in groups of four, counted from the right, so a wide pattern reads at a glance, and a folded table lists every pattern of the chosen width, up to a byte, against its signed, unsigned and hex values.

Frequently asked questions

How do I get the two's complement of a negative number?

Take the binary of the absolute value, invert every bit, then add one. This tool does it for you: type the negative decimal and it shows the finished two's complement binary and hex for the bit width you selected.

Why does -1 show as 11111111 or 0xFF?

At 8 bits, -1 is stored as all ones because inverting 00000001 gives 11111110 and adding one gives 11111111. As an unsigned pattern that is 0xFF. Wider widths simply add more leading ones, so -1 is 0xFFFF at 16 bits and 0xFFFFFFFF at 32 bits.

Can I paste a hex value and decode it?

Yes. All four fields are editable, so you can type a hex pattern (with or without a leading 0x) and it is decoded as two's complement to the signed decimal, binary and octal. At 8 bits, 0xFF becomes -1 and 0x80 becomes -128. The hex can have as many digits as the width holds (2, 4 or 8 for 8-, 16- or 32-bit — one per four bits, with a partial top digit counted as one), or fewer: a shorter one is zero-filled on the left, never sign-extended, and a line under the boxes shows the full pattern it was read as.

Can I use a less common bit width, and see the working?

Yes. Pick another preset or type any width. The working shows the invert-then-add-one steps, and the same pattern is also read as an unsigned number.

Does it show octal and one's complement, and say which width would fit?

Yes. An “Octal” box sits under the hex and is editable like the others — its digits are read as the same width-bit pattern, so a top digit past the width is refused — and a read-only “One's complement binary” box shows the same number in one's complement beside two's; the most negative value has no one's-complement form, and the page says why. A number too big for the width ends its message with the width that would hold it.

Can it space out a long pattern, or show every pattern in a table?

Yes. The grouping checkbox above the boxes, off by default, spaces the computed binary, hex and one’s complement and the working in groups of four, counted from the right, while the box you are typing in is left as typed; Copy still takes the unbroken pattern, a grouped pattern typed back in reads the same, and Copy link keeps the choice. Under the tool, the folded table of every pattern at the chosen width gives each one’s binary, signed, unsigned and hex value in pattern order — the positives first, then the negatives, as printed tables have them — with the current value’s row marked. It goes up to a byte wide; at a wider width it says how many rows the table would need instead.