How to use the Excess-3 to Binary tool
- Enter the Excess-3 code in the Excess-3 box as groups of four bits, for example 0111 1000.
- Select Convert. Spaces between groups are optional.
- Read the binary integer in the Result box. For the sample input it is 101101, which is decimal 45.
- Select Copy to copy the binary value, or Example to reload the sample groups.
How Excess-3 code works
Excess-3, or XS-3, is a way of storing decimal digits in four bits each. It takes the ordinary BCD value of a digit and adds 3. Digit 0 is stored as 0011, digit 5 as 1000 and digit 9 as 1100. The code is unweighted: the bit positions do not have fixed values you can sum.
The offset gives the code a useful symmetry. Inverting all four bits of a digit produces the code of its nines' complement. Digit 4 is 0111, and flipping it gives 1000, the code for 5, which is 9 minus 4. Early decimal machines such as the UNIVAC I used Excess-3, in part because that made subtraction cheap to build.
What this Excess-3 to binary conversion does
The conversion runs in three stages. First the input is cut into groups of four bits. Second, 3 is subtracted from each group to recover a decimal digit. Third, the digits are read together as one decimal number, and that number is written in base 2.
Note that the result is the binary form of the whole number, not a digit-by-digit translation. Leading zero digits vanish in the process: 0011 0011 1010 decodes to 007 and prints 111.
Excess-3: 0111 1000
minus 3: 0100 0101
digits: 4 5
decimal: 45
binary: 101101Valid groups and error messages
Only ten of the sixteen 4-bit patterns are legal Excess-3 digits. Input may contain spaces, line breaks and a leading 0b, all of which are ignored. The total length can be from 4 to 65,536 bits, and decoding happens locally in your browser.
- Valid: 0011, 0100, 0101, 0110, 0111, 1000, 1001, 1010, 1011 and 1100, for digits 0 to 9.
- Invalid: 0000, 0001 and 0010, which fall below the code for 0.
- Invalid: 1101, 1110 and 1111, which lie above the code for 9.
- An invalid group stops the conversion with a message such as Invalid digit group: 0000.
- A bit count that is not a multiple of four returns Enter complete groups of four bits.
Why Excess-3 was used
Besides the complement trick, Excess-3 has no all-zeros code word. A disconnected or dead data line reads as 0000, which is invalid, so the fault is noticed. Adding two Excess-3 digits also produces a binary carry exactly when the decimal sum passes 9, because the two offsets add up to 6.
If your groups are plain 8421 BCD without the offset, use the BCD to Binary tool.
Frequently asked questions
What is 0111 1000 in binary?
It is 101101. The groups 0111 and 1000 are Excess-3 for the digits 4 and 5, so the number is 45, and 45 in binary is 101101.
How do I decode Excess-3 by hand?
Split the bits into groups of four, convert each group to its value from 3 to 12, and subtract 3. The results are the decimal digits in order. Convert the full decimal number to base 2 if you need binary.
Why does 0000 give an error?
0000 would mean the digit minus 3, which does not exist. The lowest legal group is 0011, standing for 0. The tool reports the exact group so you can find the mistake in your input.
What is the difference between Excess-3 and BCD?
Both use four bits per decimal digit. BCD stores the digit value itself, 0000 to 1001. Excess-3 stores the digit plus 3, 0011 to 1100. So the digit 2 is 0010 in BCD and 0101 in Excess-3.
Does the output keep one group per digit?
No. The output is a single binary integer with no grouping and no leading zeros. 0100 0011 0011 decodes to 100 and is printed as 1100100.
Is Excess-3 a self-complementing code?
Yes. Inverting every bit of an Excess-3 digit gives the code for 9 minus that digit. For example 0011 (0) inverts to 1100 (9). Plain 8421 BCD lacks this property.