Two’s (2’s) Complement Calculator (Binary & Signed Integer)
Convert signed decimal integers to Two’s Complement binary, 1’s complement, and hexadecimal across 8-bit, 16-bit, and 32-bit registers.
How to Use the Two’s (2’s) Complement Calculator (Binary & Signed Integer)
Two’s complement is the universal mathematical standard used by modern computer processors (ALUs) to represent signed positive and negative integers in binary. Unlike sign-magnitude or one’s complement systems—which suffer from having two distinct representations for zero (+0 and -0)—two’s complement has a single unique zero and allows hardware adders to perform subtraction using standard binary addition circuitry.
Formula and Calculation Methodology
- n: Number of bits in the CPU register (e.g., 8, 16, or 32 bits)
- ~|x|: One’s complement (inverting all 0s to 1s and 1s to 0s)
- + 1: Adding 1 to the least significant bit (LSB) of the 1’s complement
To find the two’s complement of a negative number by hand, first write the positive magnitude in binary padded to your target bit width (such as 8 bits), invert every bit from 0 to 1 and 1 to 0 (producing the 1’s complement), and finally add 1 to the least significant bit. The most significant bit (leftmost bit) serves as the sign bit: 0 indicates a non-negative integer and 1 indicates a negative integer.
8-Bit Two’s Complement Signed Integer Reference Table
| Decimal Value | Sign-Magnitude | 1’s Complement | 2’s Complement | Hex |
|---|---|---|---|---|
| +127 (Max) | 0111 1111 | 0111 1111 | 0111 1111 | 0x7F |
| +1 | 0000 0001 | 0000 0001 | 0000 0001 | 0x01 |
| 0 | 0000 0000 | 0000 0000 | 0000 0000 | 0x00 |
| -1 | 1000 0001 | 1111 1110 | 1111 1111 | 0xFF |
| -42 | 1010 1010 | 1101 0101 | 1101 0110 | 0xD6 |
| -128 (Min) | N/A | N/A | 1000 0000 | 0x80 |
Frequently Asked Questions
Why is the 8-bit two’s complement range -128 to +127 instead of -127 to +127?
Because 00000000 represents zero, there is no redundant ‘-0’ bit pattern. That extra bit pattern (10000000) represents -128, giving one additional negative value.
How do you convert a negative two’s complement binary number back to decimal?
If the leftmost bit is 1, invert all bits, add 1 to the result, convert that positive binary number to decimal, and place a negative sign in front.
What causes two’s complement arithmetic overflow?
Overflow occurs when adding two positive numbers yields a negative sign bit (1) or adding two negative numbers yields a positive sign bit (0), meaning the result exceeded [-2^(n-1), 2^(n-1)-1].