Gray Code Converter
Convert between standard binary and Gray code, where each step changes only one bit.
Binary that changes one bit at a time
Gray code is an ordering of binary numbers where consecutive values differ by exactly one bit. That single-bit-change property makes it valuable in the physical world — rotary encoders, position sensors and similar hardware — because it avoids the glitches that happen when several bits try to flip at once and are read mid-transition. This converts between ordinary binary and Gray code in both directions.
Enter a value and see its Gray code, or Gray code back to binary.
Where the single-bit change matters
The problem Gray code solves is real: in a sensor reading a binary position, if going from one value to the next means several bits flipping simultaneously, a reading taken during that instant can catch some bits changed and others not, producing a wildly wrong value. Because Gray code changes only one bit per step, there is no such ambiguous moment. It also appears in error correction and certain algorithms. Converting between the two lets you work with the Gray-coded values hardware produces and translate them back to the plain binary your code expects.
Common questions
What makes Gray code special?
Consecutive values differ by exactly one bit, which avoids the glitches of several bits flipping at once.
Where is it used?
Rotary encoders and position sensors, where a mid-transition reading of ordinary binary could produce a wildly wrong value.
Is anything uploaded?
No. The conversion happens in your browser.