Gray Code Converter
Convert binary to Gray code, Gray code to binary, decimal to Gray code, and generate n-bit Gray code tables for digital logic, encoders and counters.
๐Ÿ” Field Rule: In Gray code, only one bit changes between two adjacent numbers. This makes it useful for rotary encoders, position sensors, Karnaugh maps and error-reduced digital transitions. Use this with the Binary Converter, Truth Table Generator, Boolean Algebra Calculator and K-Map Solver.
๐Ÿ” Binary โ†’ XOR With Shifted Binary โ†’ Gray Code
BINARY1011input bits XOR STEPbแตข โŠ• bแตขโ‚‹โ‚MSB stays same GRAY1110one-bit change Formula: Gray = Binary XOR (Binary shifted right by 1)
Binary Input
Group Bits
Decimal Display
Binary to Gray rule: keep the first bit the same, then XOR each binary bit with the bit before it.
Presets:
Gray Code Input
Group Bits
Decimal Display
Gray to binary rule: keep the first bit the same, then each next binary bit equals previous binary bit XOR current Gray bit.
Presets:
Decimal Number
Bit Width
Output Format
Decimal to Gray can be calculated directly using: Gray = n XOR (n shifted right by 1).
Examples:
Number of Bits
Table Style
Sequence Note
The reflected binary Gray code sequence changes only one bit from one row to the next, including wraparound from last to first.
Tables:

๐Ÿ“ Formula Reference

Binary to Gray
Gray = Binary XOR (Binary >> 1)
Bit-by-Bit Rule
Gโ‚€ = Bโ‚€, Gแตข = Bแตขโ‚‹โ‚ โŠ• Bแตข
Gray to Binary
Bโ‚€ = Gโ‚€, Bแตข = Bแตขโ‚‹โ‚ โŠ• Gแตข
Gray Table Size
Rows = 2โฟ, where n = number of bits

๐Ÿ“‹ Quick Reference

4-bit Examples
Binary 0000Gray 0000
Binary 0001Gray 0001
Binary 0010Gray 0011
Binary 1011Gray 1110
Common Uses
Rotary encodersposition
Karnaugh mapsordering
Counterslow glitches
Sequence Rows
2 bits4 rows
3 bits8 rows
4 bits16 rows
8 bits256 rows

๐Ÿ“š Digital Logic Notes

Gray code reduces transition ambiguityBecause adjacent Gray code values differ by only one bit, sensors and encoders are less likely to produce large wrong readings during transitions.
Not the same as normal binary countGray code is not weighted like normal binary. Convert it back to binary before doing arithmetic.
K-map cells use Gray orderKarnaugh map rows and columns are arranged in Gray code order so adjacent cells differ by only one variable.
Use with other logic toolsAfter converting codes, use the Truth Table Generator and K-Map Solver to verify or simplify logic.

What is a Gray Code Converter?

A Gray code converter changes normal binary numbers into Gray code, or converts Gray code back into binary. Gray code is also called reflected binary code because adjacent values change by only one bit.

How to convert binary to Gray code

Keep the most significant bit the same. Then compare each binary bit with the previous binary bit using XOR. For example, binary 1011 becomes Gray 1110.

How to convert Gray code to binary

Keep the first Gray bit as the first binary bit. Then XOR the previous binary bit with the current Gray bit to get the next binary bit.

Why is Gray code used in rotary encoders?

Rotary encoders often use Gray code because only one output bit changes between adjacent positions. This reduces the chance of reading a completely wrong value when the encoder is between two positions.

โ“ Frequently Asked Questions

Gray code is a binary numbering system where two adjacent values differ by only one bit. It is widely used in encoders, digital counters and Karnaugh maps.
Write the first binary bit as it is. Then XOR each binary bit with the previous binary bit. That gives the Gray code output.
Copy the first Gray bit as the first binary bit. For each next bit, XOR the previous binary result with the current Gray bit.
Binary 1011 converts to Gray code 1110. The first bit stays 1, then each following Gray bit is made by XORing adjacent binary bits.
Normal binary is weighted and convenient for arithmetic. Gray code is arranged so adjacent values differ by only one bit, which is useful for reducing transition errors.
Karnaugh maps use Gray code ordering so horizontally or vertically adjacent cells differ by only one variable. This makes Boolean grouping and simplification easier.
No. Gray code is not a weighted code like normal binary. It must be converted back to binary before normal arithmetic operations.