This is a two's complement calculator. Encode a signed integer to a bit pattern, or read hex/binary as signed. −1 at 8 bits is 0xFF. −52 is 0xCC. The same byte 0xFF is 255 unsigned.
Click a bit to flip it. The leftmost bit (gold ring) is the sign bit.
Click a value to copy it
Pad, invert, add 1
Two's complement add / subtract (A and B as signed decimal)
Examples — click a swatch
Same 4-bit pattern under unsigned, sign-magnitude, one's complement, and two's complement — click a row to load it
| Binary | Unsigned | Sign-magnitude | One's complement | Two's |
|---|---|---|---|---|
| 0000 | 0 | 0 | 0 | 0 |
| 0101 | 5 | 5 | 5 | 5 |
| 0111 | 7 | 7 | 7 | 7 |
| 1000 | 8 | −0 | −7 | −8 |
| 1010 | 10 | −2 | −5 | −6 |
| 1111 | 15 | −7 | −0 | −1 |
This page encodes a signed integer into a two's complement bit pattern, or reads a hex/binary pattern as signed. Widths are Auto, 4, 8, 12, 16, 32, and 64. −1 at 8 bits is 0xFF (binary 1111 1111). −52 is 0xCC. 20 is 0x14. The same bits also have an unsigned reading: 0xFF is 255. HEX, Binary, Decimal stay untranslated. This is not the hex bitwise calculator and not the unsigned hex calculator.
The pattern is TC = (2^N + X) mod 2^N. 8-bit signed range is −128…127; 4-bit is −8…7. Hex/binary shorter than the width are zero-padded, not sign-extended. Negating 0x80 at 8 bits stays 0x80: +128 does not exist in that width. Related: IEEE 754, endian converter.
The range is asymmetric. Invert 1000 0000 and add 1 and you get 1000 0000 again. The mathematical +128 does not fit.
Both, depending on how you read it. This page always shows the signed two's complement value and the unsigned reading of the same bits.
Every bit of the current pattern flipped, with no +1. Two's complement of a negative number is invert the magnitude then add 1. Hardware subtraction uses that +1 form, which is why two's complement won over one's complement and sign-magnitude.