Sign-Magnitude / One's / Two's Complement Converter
The three codes of a signed integer — sign-magnitude, one's complement, two's complement at a glance.
What it does: Convert a signed integer into sign-magnitude, one's complement, and two's complement (at a chosen bit width).
When to use it: When learning computer organization, debugging signed numbers, or reading negative values in registers.
MEANS Computers store signed integers in two's complement; all three codes match for positive numbers and only differ for negative ones.
No history yet. Each calculation is automatically saved to this device.
How to use the sign-magnitude / complement converter
Enter an integer, pick the bit width.
- 01
Enter an integer
Positive or negative, e.g.
-5,127. - 02
Pick the bit width
8 / 16 / 32 bits are common. It sets the representable range.
- 03
Read the three codes
Get sign-magnitude, one's complement, and two's complement at once (plus the two's-complement hex).
Three-code definitions
All three are identical for positive numbers; they only differ for negative numbers.
| Code | Positive | Negative |
|---|---|---|
| Sign-magnitude | sign bit 0 + magnitude | sign bit 1 + magnitude |
| One's complement | same as sign-magnitude | sign bit unchanged, magnitude bits inverted |
| Two's complement | same as sign-magnitude | one's complement + 1 (= 2ⁿ + value) |
Standard definitions from computer organization.
Common questions, answered in 3 minutes
Why do computers use two's complement?
Two's complement unifies addition and subtraction into addition and has only one zero (sign-magnitude / one's complement have +0 and −0), so the hardware is simplest — that's why CPUs store signed integers in two's complement.
Why doesn't −128 have a sign-magnitude / one's complement form?
8-bit sign-magnitude / one's complement range is −127 to +127 (one bit is reserved for the sign), while two's complement can represent one extra value, −128. So −128 only has the two's complement 10000000; sign-magnitude / one's complement would need 9 bits.
How do I find a two's complement quickly?
For a negative number: invert all bits then add 1, or "find the first 1 from the right and invert everything to its left." This tool gives the result directly.
What happens if I pick the wrong bit width?
Too few bits causes an overflow error (e.g. 8 bits can't hold 200). Choose 8/16/32 to fit the value range.
Standards and sources referenced by this tool
| Item | Value / Formula | Source |
|---|---|---|
| Sign-magnitude / one's / two's complement | sign-magnitude / one's complement / two's complement | computer organization |
Per standard computer-organization definitions, no external API.