How to use the Signed magnitude to Binary tool
- Enter the word in the Signed magnitude word box. The first digit is the sign and the remaining digits are the magnitude.
- Select Convert. Select Example to convert the sample 10101001.
- Read the two's complement word, which has the same width, in the Result box.
- Select Copy to copy the bits, or Clear to convert another word.
Signed magnitude versus two's complement
Signed magnitude stores a number the way people write it: one sign bit, 0 for plus and 1 for minus, followed by the absolute value in plain binary. It is easy to read but awkward for hardware, because addition needs to compare signs and there are two encodings of zero.
Two's complement represents a negative number -x as 2^n - x in an n-bit word. Addition and subtraction then work with the same circuit for all sign combinations, and zero has a single encoding. Positive numbers look identical in both systems, so only words with a sign bit of 1 change in this conversion.
How the signed magnitude to binary conversion works
The converter takes the first digit as the sign and reads the rest as an unsigned magnitude. If the sign is 0, the word is returned unchanged. If the sign is 1, it negates the magnitude and wraps the result to the input width, which is the same as inverting every bit of the positive value and adding 1.
For 10101001 the sign is 1 and the magnitude 0101001 is 41, so the value is -41. Plus 41 in eight bits is 00101001. Inverting gives 11010110, and adding 1 gives 11010111.
10101001 → 11010111 (-41)
00101001 → 00101001 (+41, unchanged)
10000000 → 00000000 (negative zero)
1101 → 1011 (-5 in 4 bits)Width, range and edge cases
The word width is taken from the number of digits you enter, so type the full register width.
- The output always has as many bits as the input.
- An n-bit signed magnitude word covers -(2^(n-1) - 1) to +(2^(n-1) - 1). Every such value fits in n-bit two's complement, so the conversion never overflows.
- Negative zero, a sign bit of 1 with an all-zero magnitude, converts to all zeros.
- The most negative two's complement pattern, 1 followed by zeros, is never produced because signed magnitude cannot express that value.
- A one-digit input has no magnitude bits and always returns 0.
- Input may be 1 to 65,536 binary digits. Spaces and a 0b prefix are ignored.
Where signed magnitude data comes from
IEEE 754 floating-point numbers use a sign bit with a separate magnitude for the significand, which is why they have both +0 and -0. Some analog-to-digital converters, sensors and DSP data formats report readings as sign plus magnitude. Before doing arithmetic on such values in ordinary integer types, convert them to two's complement.
Frequently asked questions
What is 10000001 in two's complement?
As a signed magnitude word it means -1: sign bit 1, magnitude 0000001. The 8-bit two's complement form of -1 is 11111111, which is what the converter returns.
Why does a positive number come back unchanged?
When the sign bit is 0, signed magnitude and two's complement use the same bits: a leading 0 followed by the value in binary. Only negative words need re-encoding.
What happens to negative zero?
Signed magnitude has two zeros, 0000 and 1000 in four bits. Two's complement has one. The converter maps both to the all-zero word, so the sign of a negative zero is dropped.
Does the result show the decimal value?
No, the output is only the two's complement bit pattern. To read it as a number, paste the result into the Binary Signed unsigned Converter, which prints the signed and unsigned decimal values.
How do I convert in the other direction?
Use the Binary Signed magnitude Converter. It takes a two's complement word and returns sign and magnitude at the same width. It reports an error for the one value that does not fit, the most negative number.
Can I enter the number in decimal or hex?
No. The field takes binary digits only. The sign must be the first bit of the word, not a minus character, and the width is whatever number of digits you supply.