Binary to Gray code converter
Gray code changes only one bit between neighbouring values, which is why rotary encoders and Karnaugh maps use it.
Loading the tool…
Processing and privacy: The result is calculated inside your browser and your data is not sent to any server.
How to use it
- Enter binary number.
- The result appears straight away and updates as you edit.
- Copy the result, or copy a link that keeps the same values to share it.
How it is calculated
The leftmost bit stays the same, and every later bit is the XOR of that binary bit and the one before it. In short, G = B XOR (B >> 1).
Example
Inputs: Binary number = 1011. Result: Gray code: 1110.
1011
1110
Limits and caveats
- Keeps the bit width you typed, including leading zeros.
- Uses the standard binary-reflected Gray code, not other Gray code variants.
Questions about this tool
How do I convert 1011 to Gray code?
Keep the first bit 1, then 1 XOR 0 = 1, 0 XOR 1 = 1, 1 XOR 1 = 0, giving 1110.
Why do rotary encoders use Gray code?
Only one bit changes between positions, so there are no false readings while several bits switch at once.
Does the value change?
Gray code is another way to write the same position, not a new number. The reverse tool turns it back into binary.
