All Tools
T

Two's Complement Calculator

Convert between signed decimal integers and exact-width two's complement binary without silent padding, wrapping, or truncation.

Bit width

Preset widths only. Binary input must match the selected width exactly after normalization.

Signed decimal
Enter a whole number from the selected signed range.

Allowed range at 8 bits: -128 to 127.

Binary (two's complement)
Accepts optional 0b, spaces, and underscores before validation.

After normalization, the bit string must be exactly 8 bits. Shorter input is rejected instead of padded.

Enter a decimal or binary value to compute signed, unsigned, and hexadecimal views.
Derived outputs
Machine-readable values only. Copy buttons use the plain ungrouped value.
Results appear here after a valid input. Out-of-range decimals and wrong-length binary values hard-fail instead of wrapping.
Signed range
Fixed-width two's complement values always depend on the active bit width.

Min

-128

Max

127

Fits selected width

Waiting for input

Signed range rule: -2^7 through 2^7 - 1. The leading bit contributes negative weight.

Special cases
Two values deserve extra attention in two's complement math.
Valid inputs will call out the special zero case and the minimum negative value when they apply.

Two's Complement Calculator: Signed Decimal and Fixed-Width Binary

Two's complement is the standard fixed-width way computers store signed integers. The width matters every time. 11111111 can mean -1 at 8 bits, but 0000000011111111 means 255 at 16 bits because the leading bit changed.

This tool converts between signed decimal and exact-width two's complement binary for 4, 8, 12, 16, 32, and 64 bits. It runs entirely in the browser, uses exact BigInt math, and hard-fails invalid input instead of silently padding, truncating, or wrapping values.

Why width is not optional

An n-bit two's complement value represents the signed range -2^(n-1) through 2^(n-1)-1.

That range is why decimal 128 does not fit in signed 8-bit two's complement. The correct behavior is an error, not automatic wraparound.

The same rule explains why shorter binary input is rejected. If you type 1111, the calculator cannot safely guess whether you meant 4-bit -1, 8-bit 15 after left-padding, or something else entirely. Exact-width semantics prevent wrong assumptions.

How signed values are interpreted

For non-negative numbers, the binary bits work like ordinary unsigned binary with a leading 0.

For negative numbers, the most significant bit is not just a sign marker. It has negative weight. In an n-bit value, the signed value is:

-bit[n-1] * 2^(n-1) + sum(bit[i] * 2^i)

That is why 11111111 at 8 bits is -1:

The same pattern works for every negative two's complement value.

Decimal to two's complement

To encode a negative signed integer into n bits:

  1. Convert the magnitude to binary.
  2. Left-pad to the selected width.
  3. Invert every bit.
  4. Add 1.

Example: -42 at 8 bits

That final pattern is why the calculator shows:

Binary to signed decimal

When the leading bit is 0, the signed and unsigned interpretations match.

When the leading bit is 1, interpret the full bit pattern as unsigned first, then subtract 2^n. For 11110000 at 8 bits:

This is the formal fixed-width definition. It is clearer than thinking of the leading bit as a separate sign flag.

The two special cases

Zero

Zero is all zeros at every width. Two's complement solved an older signed-binary problem by giving zero exactly one representation. Negating zero still produces zero.

Minimum negative value

Every width has one minimum negative value:

This value is special because negating it in the same width overflows. The positive counterpart needs one more bit than the width allows, so the same bit pattern comes back.

Why hex and unsigned views help

Signed decimal answers the math question, but developers often need the other interpretations too.

Showing all three together makes it easier to debug low-level code and avoid confusing representation with arithmetic negation.

Common mistakes this tool avoids

Troubleshooting

Why does 11111111 mean -1? — At 8 bits, 11111111 is unsigned 255. Two's complement signed interpretation subtracts 2^8 = 256, so 255 - 256 = -1.

Why can 10000000 mean -128? — In 8-bit two's complement, the leading bit has weight -128 and every other bit is 0, so the total is -128. It is also the minimum negative value for that width.

Why is shorter binary input rejected? — Two's complement is width-dependent. 1111 is not safely interchangeable with 00001111. Rejecting short input avoids guessing missing leading bits and changing the signed meaning.

Why does decimal 128 fail at 8 bits? — Signed 8-bit two's complement only allows values from -128 to 127. 128 needs a wider signed width.

Why does the minimum negative value warn about overflow? — Negating the minimum value in the same width would require one more positive bit than the width has, so the hardware-style result wraps back to the same bit pattern.