Enter an integer to automatically compute its sign-magnitude, one's complement, and two's complement binary representations
Input Decimal Integer
Bit Width
Result
Step-by-Step Derivation
Two's Complement Principle
Sign-magnitude: MSB = sign bit (0 positive, 1 negative), remaining bits = absolute value
One's complement (negative): sign bit unchanged, remaining bits flipped
Two's complement (negative): one's complement + 1
For positive numbers: sign-magnitude = one's complement = two's complement
Computers use two's complement to store signed integers, which allows subtraction to be converted to addition.
⚠The input integer must fit within the selected bit width. 8-bit range: -128~127, 16-bit: -32768~32767, 32-bit: -2147483648~2147483647.
What Are Sign-Magnitude, One's Complement, and Two's Complement?
Sign-magnitude, one's complement, and two's complement are three machine-number encoding schemes for signed integers. Two's complement is the standard encoding used by modern computers, allowing the CPU to handle both addition and subtraction using the same addition circuit.
Sign-Magnitude
MSB is the sign bit (0 positive, 1 negative), remaining bits represent the absolute value. For example, +5 = 00000101, -5 = 10000101 (8-bit).
One's Complement
For positives, same as sign-magnitude. For negatives, keep the sign bit as 1, flip all absolute-value bits. For example, -5 one's complement = 11111010.
Two's Complement
For positives, same as sign-magnitude. For negatives, add 1 to one's complement. For example, -5 two's complement = 11111010 + 1 = 11111011.
Why Use Two's Complement
Two's complement eliminates the ambiguity of ±0 and unifies addition and subtraction. a - b = a + (two's complement of b). The CPU only needs an adder. 8-bit range: -128~127.
💡 Teaching Example: Find the 8-bit sign-magnitude, one's complement, and two's complement of -5. Sign-magnitude: 5 in binary = 00000101 → set sign bit to 1 → 10000101. One's complement: keep sign bit, flip rest → 11111010. Two's complement: one's complement + 1 → 11111011. Verification: -5's two's complement + 5's two's complement = 11111011 + 00000101 = 00000000 (carry discarded) = 0.
What are sign-magnitude, one's complement, and two's complement?▼
Sign-magnitude: sign bit (MSB 0=positive, 1=negative) + absolute value. One's complement: same as sign-magnitude for positives; for negatives, keep the sign bit and flip all other bits. Two's complement: same as sign-magnitude for positives; for negatives, add 1 to one's complement. Computers store integers in two's complement.
Why do computers use two's complement instead of sign-magnitude?▼
Two's complement unifies subtraction as addition (a-b = a + two's complement of -b), greatly simplifying CPU hardware design. It also avoids the ambiguity of having both +0 and -0. For example, in 8-bit two's complement, -128 = 10000000 and -1 = 11111111.
How do you convert two's complement back to sign-magnitude?▼
The method is the same as finding the two's complement: if the sign bit is 0 (positive), the two's complement equals the sign-magnitude. If the sign bit is 1 (negative), keep the sign bit, flip all other bits, then add 1 to get the sign-magnitude.
What is the range of an 8-bit two's complement number?▼
The range of 8-bit two's complement is -128 to +127. Positive numbers are 0~127 (00000000~01111111), negative numbers are -1~-128 (11111111~10000000). The reason -128's two's complement is 10000000 while +128 cannot be represented is that the MSB also serves as the sign bit.
Free online calculators and tools covering mathematics, unit conversion, text processing, and daily life. Accurate, fast, mobile-friendly, and completely free to use.