Gray Code Converter
Convert between Gray code, binary and decimal for absolute encoders.
READY
gray_code_converter.tool
READY
Enter a decimal number, e.g. 45
Decimal45
Binary (natural)00101101
Gray code (binary)00111011
Gray code (hex)0x3B
// HOW IT WORKS
Gray code changes only one bit between consecutive values, which makes it robust for absolute encoders. The tool converts between Gray code, binary and decimal.
Formula
binary → gray: g = b XOR (b >> 1) gray → binary: b_i = g_i XOR b_(i+1)
Example
Decimal 5 = binary 101 → Gray 111; Gray 111 → binary 101 = 5.
Notes
- Only one bit flips per step, so a misread at the transition causes at most an off-by-one error.
- Decoding is iterative from the MSB downward (XOR running from the top bit).