Two’s Complement Calculator
Convert signed decimal, binary and hex at 8, 16, 32 or 64 bits. See both signed and unsigned readings and the calculation steps.
Inspect & edit bits
Most significant firstSelect a group to highlight Binary. Click a bit, or press Space, to toggle it.
Enter a value to inspect its bits.
Two’s complement calculation steps
Enter a valid integer to see the calculation steps.
Signed and unsigned decimal show the same bits. Values outside the chosen width are reported without wrapping or truncation.
/usage
Decimal to two’s complement, and back
- Choose a bit width. The same binary or hex pattern can mean different numbers at different widths.
- Enter a signed decimal to encode it, or enter binary or hex to read that pattern as a signed integer. Unsigned decimal shows the other interpretation of the same bits.
- Copy any representation, edit individual bits, or open Two’s complement calculation steps to follow the working.
This 2’s complement calculator uses exact integer arithmetic, including the full 64-bit range. Hex accepts a 0x prefix; binary accepts 0b. Spaces and underscores are accepted in bit patterns, and short patterns are padded with leading zeros. Out-of-range decimal values are reported without widening, wrapping or truncating.
Bookmark 8-bit, 16-bit, 32-bit or 64-bit conversion. Bookmarks save settings, not entered values. For fractional numbers, use the IEEE 754 floating point converter.
/examples
Encode −42 in 8-bit two’s complement
- Write the magnitude 42 in binary:
00101010. - Invert every bit:
11010101. - Add one:
11010110, or hexD6.
The unsigned reading is 214. To decode the signed value, the first bit is 1, so subtract 2^8: 214 − 256 = −42. For a nonnegative number, write its binary value and pad with zeros; no inversion is needed.
Encoding a negative decimal and negating a raw bit pattern are different tasks. This calculator encodes and decodes the selected signed value; entering 11010110 reads −42 rather than taking its opposite. Negating the minimum signed value overflows the same width.
/interpretation
Why FF can mean −1 or 255
In 8-bit two’s complement the leading bit has weight −128. Therefore 11111111 is −128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = −1. Read as unsigned, those same bits are 255.
At 16 bits the short input FF is zero-padded to 0000000011111111, which is signed 255. To encode −1 at 16 bits, use FFFF. Padding a short input is not sign extension.
/ranges
Signed and unsigned integer ranges
For n bits, two’s complement ranges from −2^(n−1) to 2^(n−1) − 1. The unsigned range starts at 0 and ends at 2^n − 1. There is one zero and one extra negative value.
| Width | Signed minimum | Signed maximum | Unsigned maximum |
|---|---|---|---|
| 8-bit | -128 | 127 | 255 |
| 16-bit | -32768 | 32767 | 65535 |
| 32-bit | -2147483648 | 2147483647 | 4294967295 |
| 64-bit | -9223372036854775808 | 9223372036854775807 | 18446744073709551615 |
In 8 bits, 255 is valid in Unsigned decimal and reads as signed −1; it is outside the Signed decimal range. The 64-bit unsigned maximum 18446744073709551615 is handled exactly and reads as signed −1.