Gray Code Converter
Binary ⇄ Gray code — adjacent values differ by only one bit.
What it does: Convert between binary and Gray code.
When to use it: When building encoders, ADCs or state machines that need to avoid race conditions.
MEANS In Gray code, adjacent values flip only one bit, making hardware readings more stable.
No history yet. Each calculation is automatically saved to this device.
How to use the Gray code converter
Pick a direction and enter a value.
- 01
Pick a direction
Binary → Gray or Gray → Binary.
- 02
Enter a decimal value
Type the number to convert (the "source" for the chosen direction).
- 03
Read both codes
Both the binary and Gray code bit strings are shown at once.
Common questions, answered in 3 minutes
What is Gray code used for?
Adjacent values differ by only one bit. Used in rotary encoders, ADCs and state machines, it avoids the transient glitch codes caused by several bits flipping at once.
How do I get Gray code from binary?
g = n XOR (n shifted right by 1 bit). The most significant bit stays the same; every other bit is XORed with the bit above it.
Can you do arithmetic in Gray code?
Not directly. You usually convert back to binary, compute, then convert the result to Gray.
Standards and sources referenced by this tool
| Item | Value / Formula | Source |
|---|---|---|
| Gray code | g = n XOR (n>>1) | Reflected binary code |
Exact via BigInt, no external API.