Decimal β 2's Complement
Enter a signed decimal integer and choose a bit width from 2 to 64.
2's Complement Binary β Decimal
Enter a binary value (spaces and underscores allowed). Bit width is inferred from the binary length.
What Is 2's Complement?
2's complement is the standard way computers represent signed integers in binary. Instead of keeping a separate sign symbol, the sign is encoded directly into the bits. This design makes arithmetic hardware simpler because addition and subtraction can use the same circuits for both positive and negative values.
In an n-bit 2's complement system, the leftmost bit is the sign bit. If that bit is 0, the number is non-negative. If it is 1, the number is negative. The representable range is:
- Minimum: -2n-1
- Maximum: 2n-1 - 1
How to Use This 2s Complement Calculator
1) Convert decimal to 2's complement binary
Enter a decimal integer and a bit width. The calculator verifies the value fits the selected width, then returns:
- Signed decimal input
- Allowed range for that bit width
- 2's complement binary representation
- Hex representation of the same bit pattern
- Unsigned interpretation of the bit pattern
For negative values, it also shows the classic conversion steps: magnitude, invert bits (1's complement), and add 1.
2) Convert binary back to decimal
Enter a binary string such as 11110110. The calculator infers bit width from the number of bits, then reports:
- Signed decimal value (2's complement interpretation)
- Unsigned decimal value
- Hex value
- Sign bit and a short decode explanation for negative values
Worked Examples
Example A: Decimal -18 in 8 bits
18 in binary is 00010010. Invert bits to get 11101101, then add 1 to get
11101110. So -18 in 8-bit 2's complement is 11101110.
Example B: Binary 11101110 to decimal
The sign bit is 1, so this is negative in 2's complement. Invert the bits:
00010001. Add 1: 00010010 which is 18. Therefore, the signed value is -18.
Why Bit Width Matters
Bit width defines range and overflow behavior. The same bit pattern can represent very different numbers depending on width.
For instance, 11111111 means:
- 255 if interpreted as unsigned 8-bit
- -1 if interpreted as signed 2's complement 8-bit
If you try to encode a number outside the allowed range, overflow occurs and the stored bit pattern wraps modulo 2n. That is why selecting the correct width is critical in embedded systems, networking, CPU design, and low-level debugging.
Common Mistakes
- Forgetting to choose the correct bit width before conversion.
- Assuming all leading 1s are βextraβ; in signed math they are sign extension.
- Confusing unsigned interpretation with 2's complement signed interpretation.
- Using decimal values outside range and expecting exact storage without overflow.
Where 2's Complement Is Used
2's complement appears in almost every modern computing domain: microcontrollers, operating systems, compilers, instruction sets, binary protocols, and digital signal processing. If you work with C/C++, assembly, hardware interfaces, or packet formats, understanding signed binary arithmetic will save you hours of debugging.
Quick FAQ
Is 2's complement the same as signed magnitude?
No. Signed magnitude stores sign separately; 2's complement integrates sign into the bit pattern and supports simpler arithmetic.
Why is there one extra negative number in range?
Because zero takes one code, leaving 2n-1 codes split unevenly. So range is -2n-1 to 2n-1-1.
Can I use this tool for 16, 32, and 64-bit values?
Yes. The decimal converter supports 2 through 64 bits, and binary conversion supports up to 64 bits.