Excess-3 code (XS-3, or the Stibitz code) is a binary-coded decimal representation in which every decimal digit is stored as its value plus three, written in four bits. This converter encodes decimal numbers to Excess-3 and decodes Excess-3 nibbles back to decimal, showing the offset for each digit.
Why learn Excess-3 today?
Excess-3 is a classic topic in digital electronics curricula because it illustrates two important ideas in one compact encoding: the self-complementing property (subtraction via inversion) and why non-trivial encodings exist beyond simple binary or BCD. While Excess-3 is rarely used in new hardware, understanding it clarifies why early computing pioneers made the design choices they did, and it appears regularly in undergraduate exams, textbook exercises, and digital circuit design problems.
How it works
To encode, the tool takes each decimal digit, adds three, and writes the result as a 4-bit binary number. So 0 becomes 0011 (0 + 3), 5 becomes 1000 (5 + 3), and 9 becomes 1100 (9 + 3). Each digit always uses exactly one nibble, and the nibbles are joined to form the code.
To decode, the input is split into 4-bit groups. Each group is read as a binary value, three is subtracted, and the difference is the decimal digit. A group whose value falls outside the range 3 to 12 is not a legal Excess-3 code, so the decoder reports it instead of producing a wrong digit.
The self-complementing property
The reason for the offset of three is elegant. In Excess-3 the bitwise complement of a digit’s nibble gives the nines complement of that digit. For example digit 2 is 0101; inverting the bits gives 1010, which is 10 in binary and decodes to 10 - 3 = 7, exactly the nines complement of 2. This let early relay computers, including those built by George Stibitz at Bell Labs, perform decimal subtraction using only addition and bit inversion.
Worked example
The number 259 encodes digit by digit:
2 -> 2 + 3 = 5 -> 0101
5 -> 5 + 3 = 8 -> 1000
9 -> 9 + 3 = 12 -> 1100
So 259 in Excess-3 is 0101 1000 1100. Decoding reverses each step. Everything is computed locally in your browser.
Comparing Excess-3 to plain BCD
Plain BCD (8421 code) stores each decimal digit directly in four bits, with 0 = 0000 and 9 = 1001. The codes 1010 through 1111 are unused. Excess-3 shifts the used range up by three, so the valid codes run from 0011 to 1100. This symmetry around the midpoint (0111/1000) is precisely what enables the self-complementing property.
Another advantage of Excess-3 in historic hardware: because no valid digit is encoded as 0000, a wire that fails to the zero state (common in relay circuits) is immediately detectable as an error rather than producing a false “zero” digit silently.
| Decimal | Plain BCD | Excess-3 |
|---|---|---|
| 0 | 0000 | 0011 |
| 3 | 0011 | 0110 |
| 5 | 0101 | 1000 |
| 9 | 1001 | 1100 |
The nines complement relationship
Adding two BCD numbers with Excess-3 has a neat property when you need the nines complement (needed for subtraction via addition). Inverting all bits of an Excess-3 digit gives the Excess-3 encoding of its nines complement, without any additional logic. For example digit 4 is 0111 in Excess-3; inverting gives 1000, which is digit 5 — and 4 + 5 = 9, confirming the complement. This let George Stibitz build decimal subtraction into the Bell Labs relay computers using only adder circuits and bit inverters.