Skip to content
ENExplore Calculators

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

  1. 1Values used
  2. 2Binary to Gray
  3. 3Gray code= 1101
  4. 4Gray code as a decimal= 13
  5. 5Ordinary binary= 1001
  6. 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.

Gray Code Calculator | Calcrivo