Free exact browser converter
BCD to Gray Code Converter
Convert validated 8421 BCD digits to reflected binary Gray code online. Reject invalid 1010-1111 nibbles and keep exact integer arithmetic.
Interactive tool
Convert BCD to Gray Code
Ready
Choose a clear output representation.
Detailed conversion guide
How to Convert BCD to Gray Code
Validate each four-bit BCD nibble, join the decoded decimal digits, then encode that exact integer as reflected binary Gray code. BCD 0001 0000 is decimal 10 and becomes Gray 1111.
BCD is a decimal-digit encoding, while Gray code is an integer code in which adjacent values differ by one bit. The conversion therefore passes through the exact decimal value.
| Input | Output | Meaning |
|---|---|---|
0000 | 0 | decimal 0 |
0001 | 1 | decimal 1 |
0001 0000 | 1111 | BCD 10 |
0101 1001 | 100110 | BCD 59 |
BCD Validation before Gray Encoding
The algorithm validates the representation before exact integer conversion, so malformed input never produces a plausible partial answer.
const digits = groups.map(g => parseInt(g, 2));
if (digits.some(d => d > 9)) throw Error('invalid BCD');
const n = BigInt(digits.join(''));
const gray = n ^ (n >> 1n);Invalid BCD Nibbles and Leading Decimal Zeros
1010 through 1111 are not valid 8421 BCD digits. The converter also rejects incomplete nibbles and non-binary characters.
Leading BCD zeros do not change the integer, so the Gray output uses the minimal bit width. No signed BCD variant is inferred.
Related converters
Continue with exact representation converters
Use one canonical page for the precise input and output direction you need.