Convert two's complement

Decode or encode a signed integer as a fixed-width two’s-complement bit pattern.

freeworks offlinenothing uploaded
ToolTwo's Complement Converter
Input
Output

How it works

For width w, the signed interval is −2^(w−1) through 2^(w−1)−1. Decimal input is reduced modulo 2^w and decoded by subtracting 2^w when the top bit is set; binary input reverses that interpretation and is padded to the selected width.

  • Eight bits is the initial width because it is a byte.
  • Overflow is reported while the wrapped bit pattern remains visible.

Worked example

-5 at 8 bits
A negative number, small enough to fit
Input
											Value: -5
Bit width: 8
Direction: decimalToBinary
										
Output
												Requested value: -5
Stored value: -5
Binary pattern: 11111011
Hex pattern: fb
Bit width: 8
Min value: -128
Max value: 127
Overflow: no
Overflow message: 
											

When to use this

Systems lessons decode signed bytes, compiler exercises inspect register widths, and protocol debugging compares binary and hexadecimal fields.

Edge cases

  • −1 becomes all ones at every supported width rather than a minus sign followed by magnitude bits.
  • 128 cannot be positive in signed 8-bit form and is flagged while wrapping to 10000000.
  • A binary pattern with the wrong number of bits is rejected instead of silently padded or truncated.