Free browser converter
Decimal to Gray Code Converter
Convert a non-negative decimal integer to reflected binary Gray code with exact BigInt arithmetic and an optional four-bit display width.
Interactive tool
Convert decimal integers to Gray code
Ready
Choose the exact data representation; the tool never guesses an encoding.
Detailed conversion guide
How to Convert Decimal to Gray Code
First express the decimal integer as binary. Then XOR that binary value with itself shifted right by one bit: gray = n XOR (n >> 1).
Decimal 10 is binary 1010. Shifting gives 0101, and 1010 XOR 0101 produces Gray code 1111. Adjacent Gray values differ by one bit.
| Input | Output | Meaning |
|---|---|---|
0 | 0 | zero |
1 | 1 | one bit |
10 | 1111 | 1010 XOR 0101 |
15 | 1000 | 1111 XOR 0111 |
Decimal to Gray Code with BigInt
BigInt preserves integers above JavaScript's safe Number limit. The XOR formula is exact and does not use floating-point arithmetic.
const value = BigInt(decimal);
const gray = value ^ (value >> 1n);
const bits = gray.toString(2);Whole Numbers, Width, and Leading Zeros
This converter accepts non-negative whole numbers only. Negative values, fractions, exponential notation, commas, and prose are rejected.
Minimal width omits unnecessary leading zeros. Four-bit padding changes only presentation; it does not change the Gray code magnitude.
Related converters
Continue with related data converters
Choose the converter for the exact direction and representation you need.