Two's Complement Calculator
Convert decimal numbers to two's complement binary and decode signed binary back to decimal with configurable bit width and step-by-step explanation.
What Is Two's Complement?
Two's complement is the standard way computers represent signed integers in binary. The most significant bit (MSB) acts as the sign bit: 0 means positive, 1 means negative.
Related tools: Encode Negative Binary, Decode Negative Binary, and Binary Calculator.
How to Convert Decimal to Two's Complement
- Choose a bit width (8, 16, 32, or 64 bits).
- For positive numbers, write the binary and pad with leading zeros.
- For negative numbers, invert all bits of the absolute value and add 1.
Example: -37 in 8-bit Two's Complement
37 in binary is 100101. Invert to 011010, add 1 to get 11011011. So -37 is represented as 11011011 in 8-bit two's complement.
Frequently Asked Questions
What is the range of 8-bit signed integers?
8-bit two's complement covers -128 to 127. The positive range is one less than the negative range because zero uses the positive representation.
Why is two's complement preferred over sign-magnitude?
Two's complement lets CPUs use the same addition circuitry for signed and unsigned math. Sign-magnitude also has two representations of zero (+0 and -0).
How do I decode a negative binary number?
If the MSB is 1, invert all bits, add 1, and apply a negative sign to the result. This calculator performs that conversion automatically.
What happens if my number is out of range?
Each bit width has fixed limits. For example, 8-bit signed integers cannot represent 200 or -200. Increase the bit width or use a smaller value.