Two's Complement Calculator
Convert signed integers to two's complement binary and back, with bit width, decimal value, and hex output.
Frequently Asked Questions about the Two's Complement Calculator
What is two's complement?
Two's complement is the standard way computers store signed integers. For a width of N bits, a negative number d is stored as the unsigned value d plus 2 to the power N, which is the same as 2 to the power N minus the absolute value of d. The most significant bit acts as the sign bit: when it is 1 the value is negative, and when it is 0 the value is zero or positive. Almost every modern CPU and language (C, Java, Rust, Go) uses it.
How do I convert a negative decimal to two's complement by hand?
Take the absolute value and write it in unsigned binary, padded to the chosen bit width. Then invert every bit (change each 0 to 1 and each 1 to 0) and add 1 to the result. For example, -42 in 8-bit becomes the magnitude 00101010, inverted to 11010101, then plus 1 gives 11010110. This calculator shows that exact step trace whenever you encode a negative value.
How do I decode a two's complement bit pattern back to decimal?
Read the pattern as an unsigned number first. If the most significant bit is 0, that unsigned value is your answer. If the most significant bit is 1, subtract 2 to the power N (where N is the bit width) to get the negative value. For example, the 8-bit pattern 11010110 is unsigned 214, and since 214 is at least 128 you subtract 256 to get -42.
What range of values fits in each bit width?
An N-bit two's complement integer covers -2 to the power (N minus 1) up to 2 to the power (N minus 1) minus 1. So 8-bit holds -128 to 127, 16-bit holds -32,768 to 32,767, 32-bit holds about -2.1 billion to 2.1 billion, and 64-bit holds about -9.2 quintillion to 9.2 quintillion. This calculator rejects values outside the range instead of silently wrapping them.
Why is the most-negative value not symmetric with the most-positive?
Two's complement has one extra negative value because zero takes one of the non-negative slots. With N bits there are 2 to the power N total patterns, split so the negatives run from -2 to the power (N minus 1) while the positives stop at 2 to the power (N minus 1) minus 1. That is why 8-bit reaches -128 but only +127, and negating -128 in 8-bit overflows back to itself.
Does this handle 64-bit values accurately?
Yes. The calculator uses arbitrary-precision integer math, so 32-bit and 64-bit results stay exact even though they exceed the range where ordinary floating-point numbers lose whole-number precision. You can encode and decode the full 64-bit range, including the most-negative value -9,223,372,036,854,775,808, without rounding.
Related Calculators
More calculators in "Tech"
Uptime SLA CalculatorBitwise CalculatorColor Palette GeneratorIEEE 754 Floating Point CalculatorPassword Crack Time CalculatorEV Range Calculator
See all 98 calculators in "Tech"