Encode a signed decimal number – positive or negative – into two’s complement, one’s complement or sign-magnitude at 4 to 64 bits, with the encoding steps shown.
Show calculation steps
Processed privately in your browser — nothing you paste is uploaded, logged or stored.
Encoding a sign into bits
Storing −42 requires choosing a convention, and this encoder implements the three classical ones at widths from 4 to 64 bits. Two’s complement — invert and add one — is what every modern machine uses; one’s complement and sign-magnitude are provided for checksums, history and coursework.
The steps show the full pipeline on your number: magnitude bits, inversion where the scheme demands it, and the final pattern with its width made explicit.
Worked example
Value: −42, width 8, two’s complement |−42| = 00101010 invert 11010101 +1 11010110 Check: 11010110 unsigned is 214 = 256 − 42 ✓
| Pattern | Unsigned | Two’s c. | One’s c. | Sign-mag. |
|---|---|---|---|---|
| 00000000 | 0 | 0 | +0 | +0 |
| 00101010 | 42 | 42 | 42 | 42 |
| 01111111 | 127 | 127 | 127 | 127 |
| 10000000 | 128 | −128 | −127 | −0 |
| 10101010 | 170 | −86 | −85 | −42 |
| 11010101 | 213 | −43 | −42 | −85 |
| 11010110 | 214 | −42 | −41 | −86 |
| 11111111 | 255 | −1 | −0 | −127 |
Ranges at a glance
Two’s complement at n bits spans −2ⁿ⁻¹ … 2ⁿ⁻¹−1 — asymmetric by one, because a single zero leaves an odd number of remaining patterns. One’s complement and sign-magnitude span ±(2ⁿ⁻¹−1) with two zeros each. The encoder rejects out-of-range values naming the exact bounds, rather than wrapping silently the way a C cast would.
Why two’s complement won
One adder circuit handles signed and unsigned addition identically; comparison is mostly free; zero is unique. Those hardware economics, discovered in the 1950s, ended the format wars — but reading old formats and checksum algorithms still requires the losers, hence all three live here.
Privacy
Encoding is computed in-page; your values are never uploaded or recorded.
How to use the Decimal to Signed Binary Converter
- Type the signed decimal number, e.g. -42.
- Choose the representation and the bit width.
- Click "Encode number".
- The steps show the encoding pipeline – magnitude bits, inversion, and the +1 where two's complement requires it.
Frequently asked questions
How is a negative number turned into two's-complement bits?
Write |value| in binary at the chosen width, invert every bit, add one. For −42 at 8 bits: 00101010 → 11010101 → 11010110. The steps run this on your number, and the check line shows the pattern equals 2⁸ − 42 = 214 unsigned.
What range fits in n bits for each scheme?
Two's complement: −2ⁿ⁻¹ to 2ⁿ⁻¹−1 (8-bit: −128..127). One's complement and sign-magnitude: ±(2ⁿ⁻¹−1) (8-bit: ±127), each with two zeros. The tool rejects out-of-range values with the exact bounds named.
Why can two's complement hold −128 but not +128 at 8 bits?
The asymmetry is structural: 10000000 encodes −128, but +128 would need a ninth bit. This is why negate can overflow – negating −128 at 8 bits has no valid answer – a real bug class in C and assembly.
Which scheme should I actually use?
Two's complement, unless you are matching a legacy format – it is what every mainstream CPU uses, because addition and subtraction work on it with no special sign handling.
How do positive numbers encode?
Identically in all three schemes: plain binary padded to width with a leading 0. Only negatives distinguish the schemes – which the steps make visible if you flip the sign of your input.
Why does my value need a wider width than I expected?
The sign consumes one bit of headroom: 200 fits in 8 unsigned bits but NOT in 8-bit two's complement (max 127). Widths quote total bits, not magnitude bits.
Is the encoding computed locally?
Yes – entirely in the page. Your values stay on your device.