Two's Complement Calculator — signed binary conversion
Signed and unsigned interpretation at any register width, with overflow and carry flags.
Example: -42 as a signed 8-bit value is -42 — stored as 0xD6, or 214 read unsigned.
Check it against real silicon
Chiprun runs your firmware on an emulated microcontroller and hands back the UART output, so you can confirm these numbers rather than trusting them.
Formula
negate: invert every bit, then add oneWorked example
-42 as a signed 8-bit value is -42 — stored as 0xD6, or 214 read unsigned.
start with the magnitude
42 in binary
0010 1010
invert every bit
one's complement
1101 0101
add one
1101 0101 + 1
1101 0110
That is two's complement — and it is why addition and subtraction use the same hardware regardless of sign.
Frequently asked questions
How do I convert a negative number to two's complement?
Write the magnitude in binary, invert every bit, then add one. For −42 in 8 bits: 42 is 00101010, inverted is 11010101, plus one is 11010110 — which is 0xD6, or 214 read as unsigned.
Why use two's complement rather than a sign bit?
Because addition and subtraction then work identically whether the operands are positive or negative — the same adder handles both, with no special cases. It also gives exactly one representation of zero, unlike sign-magnitude which has +0 and −0.
Why is the negative range one larger than the positive?
Because zero takes up one of the positive slots. An 8-bit signed value spans −128 to +127: 128 negative values, zero, and 127 positive. The asymmetry means −128 has no positive counterpart, so negating it overflows.
What happens if I negate the most negative value?
You get the same value back. Negating −128 in 8-bit arithmetic gives −128, because +128 is not representable. In C this is undefined behaviour for signed types, and it is a classic bug in hand-written abs() implementations.
Related tools
Hex, Binary & Decimal Converter
Convert between hex, binary, decimal, octal and ASCII, with width-aware bit grids and endianness swapping.
Firmware
Bitwise Operation Calculator
AND, OR, XOR, NOT and shifts with a live bit grid so you can see exactly which bits moved.
Firmware
IEEE 754 Float Converter
Convert between decimal, hex and binary float32/float64, with the sign, exponent and mantissa fields broken out.
Firmware
Register Bitfield Decoder
Paste a register value and a field layout to get a decoded table — with presets for common STM32 and AVR registers.
Firmware
CRC Calculator
CRC-8, CRC-16 (CCITT, Modbus, XMODEM) and CRC-32 over hex or ASCII input, with the polynomial and shift steps explained.
Firmware
PWM Frequency & Duty Calculator
The frequency-versus-resolution trade-off made explicit, with register values for your MCU and duty-cycle counts.
Firmware