Gray code, BCD and Excess-3 converters with full tables – the classic codes of digital circuits, encoders and decimal hardware. Everything runs locally in your browser.
Your favourites
Recently used
- Binary to Gray Code ConverterConvert weighted binary to reflected Gray code with g = b XOR (b >> 1) – in a Gray sequence, consecutive values differ in exactly one bit, which kills glitches in rotary encoders.
- Gray Code to Binary ConverterConvert reflected Gray code back to weighted binary by cascading XOR from the top bit down – each binary bit is the XOR of the previous binary bit with the current Gray bit.
- Decimal to Gray Code ConverterConvert a decimal number straight to Gray code – first to binary, then one XOR pass.
- Gray Code Table GeneratorGenerate the full decimal-binary-Gray table for 2 to 6 bits.
- BCD to Decimal ConverterDecode binary-coded decimal: each 4-bit group is one decimal digit 0-9.
- Decimal to BCD ConverterEncode a decimal number as BCD – each digit becomes its own 4-bit group, so 429 becomes 0100 0010 1001.
- Excess-3 Code ConverterConvert between decimal and Excess-3 code, where each digit is stored as digit + 3 in four bits – a self-complementing code from the era of decimal arithmetic hardware.
Frequently asked questions
What is Gray code for?
An encoding where consecutive values differ by exactly one bit. That matters for rotary encoders and analogue-to-digital conversion, where several bits changing at once can be read mid-transition and produce a value that was never real.
What is a parity bit?
One extra bit making the number of ones in a word even or odd, so a single-bit error is detectable. It cannot say which bit changed and it misses two simultaneous errors, which is why real links use stronger codes.
What is the difference between a half adder and a full adder?
A half adder sums two bits and produces a carry. A full adder also accepts a carry in, which is what lets adders be chained to add multi-bit numbers. That chain is the ripple-carry adder inside every processor.
How do logic gates relate to bitwise operators?
They are the same operations at different levels. AND, OR, XOR and NOT in code apply the corresponding gate to every bit position in parallel, which is why bitwise operations are so fast: the hardware does all bits at once.
What is a truth table?
An exhaustive list of a circuit's outputs for every possible combination of inputs. Exhaustive is the point: it is a proof of behaviour rather than a sample, which is why it stays the standard way to specify small logic.
Why is XOR so useful?
Because it is its own inverse: applying the same value twice returns the original. That makes it the basis of parity, of simple checksums, of swapping without a temporary variable, and of the one-time pad.
Do these simulate a full circuit?
No. They cover the encodings and single operations that are fiddly to do by hand. Simulating a whole circuit, with timing and propagation delay, is a job for dedicated simulation software.
Digital design speaks in codes tuned for hardware: Gray code for glitch-free counting, BCD for digit-exact decimal, Excess-3 for complement-friendly arithmetic. The converters and table generator below implement each precisely, with validity checking that names any illegal group.
Useful for coursework, encoder work and reading datasheets that assume the codes.
Codes built for hardware, not arithmetic
The codes in this family exist because circuits have constraints that pure binary ignores. Gray code reorders the counting sequence so that consecutive values differ in exactly one bit. That matters on the shaft encoder of a motor or a rotary knob: if several bits changed at once, tiny timing differences between the bit sensors would produce brief garbage readings, but with Gray code the worst possible misread during a transition is one position off. The converters here show the XOR chain that maps between binary and Gray in both directions.
BCD takes the opposite trade. Instead of encoding the whole number in binary, it encodes each decimal digit separately in four bits, so 429 is stored as 0100 0010 1001. That wastes six of the sixteen patterns per digit, but it makes decimal display drivers and exact decimal arithmetic trivial — which is why calculators and seven-segment displays used it for decades. Excess-3 is BCD’s self-complementing cousin: storing each digit as digit-plus-three means inverting the bits gives the nine’s complement, a genuinely useful trick in the era of decimal arithmetic hardware.
Two details round out the family. The reflected Gray sequence is cyclic: the last code and the first also differ in just one bit, which is what lets a rotary encoder cross zero cleanly. And BCD needs its own arithmetic rule — when adding two BCD digits produces a result above nine, hardware adds six to skip the ten unused patterns, the correction the classic decimal-adjust instructions performed. The table generator here prints the full decimal, binary and Gray columns so both properties can be checked by eye.