Gray Code Calculator
Work out gray code instantly with clear inputs, formula shown and shareable results.
About Gray Code Calculator
Gray code is formed by XORing a value with itself shifted right one place. Consecutive Gray codes differ in exactly one bit, which prevents transient misreads in rotary encoders and mechanical counters.
Formula
Binary to Gray
g = v XOR (v >> 1)
Worked example
With the default values below, Gray Code Calculator returns Gray code of 1101. Change any input above and every figure here is recalculated in your browser.
Inputs used
- Binary or decimal valueminimum 0
- 9
- Display width in bitsaccepts 1–32
- 4
Results
- Gray code
- 1101
- Gray code as a decimal
- 13
- Ordinary binary
- 1001
- Bits that change when counting up by one
- 1
Step by step
- 1Values used
- 2Binary to Gray
- 3Gray code= 1101
- 4Gray code as a decimal= 13
- 5Ordinary binary= 1001
- 6Bits that change when counting up by one= 1
Assumptions and limits
- The result is derived only from the 2 inputs listed above. Anything not among them is not part of the calculation.
- In particular, this calculator does not take inflation, tax, fees or charges or compounding frequency into account.
- Figures are rounded for display to whole numbers, so totals built from several rounded parts can differ slightly from the unrounded arithmetic.
How these calculators are built and tested is described on the Methodology page. If a figure looks wrong, please report it.
Frequently Asked Questions
What is the Gray code of 9?
1001 XOR 0100 = 1101.
Why does single-bit change matter?
If several bits changed at once, a sensor reading mid-transition could return a wildly wrong value; with Gray code the worst error is one step.
Related Calculators
You might also need
- Discrete Logarithm CalculatorAlso in Discrete Math, Logic & Number Theory
- Adjacency Matrix CalculatorAlso in Discrete Math, Logic & Number Theory
- Base 64 Value CalculatorAlso in Discrete Math, Logic & Number Theory
- Bell Number CalculatorAlso in Discrete Math, Logic & Number Theory
- Binary To Decimal CalculatorAlso in Discrete Math, Logic & Number Theory
- Binary To Hexadecimal CalculatorAlso in Discrete Math, Logic & Number Theory
