Binary to Gray Code Converter
Learn how to convert binary to Gray code, one bit at a time. Copy the first binary bit, then XOR each pair of adjacent binary bits: equal bits give 0; different bits give 1. Change the input above to explore your own example.
The conversion rule
Start at the leftmost bit. The first Gray bit is copied directly. Every remaining Gray bit is the XOR of the binary bit at that position and the binary bit immediately to its left. Always compare original binary bits, even after Gray bits are written.
XOR means “exclusive OR.” Its result is 1 when its two inputs differ, and 0 when they match: 0 XOR 0 = 0, 0 XOR 1 = 1, 1 XOR 0 = 1, and 1 XOR 1 = 0.
Steps for your input
1011 → 1110
- Copy 1 to Gray bit 1. Copy 1. The Gray code built so far is 1.
- Write 1 to Gray bit 2. 1 XOR 0 = 1. The Gray code built so far is 11.
- Write 1 to Gray bit 3. 0 XOR 1 = 1. The Gray code built so far is 111.
- Write 0 to Gray bit 4. 1 XOR 1 = 0. The Gray code built so far is 1110.
What is Gray code?
Reflected binary Gray code is an ordering of bit patterns in which consecutive values differ in exactly one bit. It is useful for position encoders because a transition between adjacent positions changes only one bit.
A Gray code bit string is a code representation. Do not read it as an ordinary binary number with the same value. This lesson converts a non-negative binary bit string to reflected binary Gray code and preserves the input width.
Explore the visualization
Press Play for the complete conversion, or use the backward and forward buttons to examine individual operations. You can pause, scrub the timeline, change speed, or use fullscreen. Selected binary bits are outlined; completed Gray bits are green.
For long inputs, the player shows a moving window of bit positions so each comparison stays readable. The output strip and written steps show the complete conversion.