Binary to Gray Code Converter
Binary to Gray Code converter online. It converts your Binary code to Gray code for secure transmission of data from one place to another in a single click. Gray code, named after Frank Gray, is a binary numeral system where two successive values differ in only one bit. It is also known as the reflected binary code. Convert Gray code binary also on the same page. Simply input your Binary code and click on the convert button to view the gray code. We not only convert the code but also provide step step solutions for each input, like how users' binary code input converts to gray code. Convert binary to Gray code instantly with our free online tool. Step-by-step solutions, bidirectional conversion, and detailed explanations. Perfect for engineers, students and developers.
Gray Code Examples
Here are some examples of binary numbers and their Gray code equivalents:
Decimal | Binary | Gray Code | Bit Changes |
---|---|---|---|
0 | 000 | 000 | - |
1 | 001 | 001 | 1 bit |
2 | 010 | 011 | 1 bit |
3 | 011 | 010 | 1 bit |
4 | 100 | 110 | 1 bit |
5 | 101 | 111 | 1 bit |
6 | 110 | 101 | 1 bit |
7 | 111 | 100 | 1 bit |
What is Gray Code?
Gray code, named after Frank Gray, is a binary numeral system where two successive values differ in only one bit. This property makes it valuable in various applications, from error correction to analog-to-digital converters.
Unlike standard binary counting, where multiple bits can change between consecutive numbers (like from 011 to 100, where all bits change), Gray code ensures that only a single bit changes at each step.
This minimal-change property helps prevent errors in systems where transitions can lead to momentary incorrect states.
Binary to Gray Code Conversion Algorithm
Converting from binary to Gray code follows a simple algorithm:
- The Most Significant Bit (MSB) of the Gray code is the same as the MSB of the binary number.
- Every other bit of the Gray code is the XOR (exclusive OR) of the corresponding bit and the previous bit of the binary number.
Mathematically, for a binary number B with bits [b₀, b₁, b₂, ..., bₙ], the Gray code G with bits [g₀, g₁, g₂, ..., gₙ] is:
- g₀ = b₀
- g₁ = b₀ ⊕ b₁
- g₂ = b₁ ⊕ b₂
- ...
- gₙ = bₙ₋₁ ⊕ bₙ
Where ⊕ represents the XOR operation.
Applications of Gray Code
Gray code is used in a variety of applications, including:
- Rotary Encoders: Used in angular position sensors where a single bit error would lead to only a small error in position.
- Error Correction: Helps to minimize errors in communication systems.
- Analog-to-Digital Converters: Reduces the risk of misreading during transitions.
- Genetic Algorithms: Used in some evolutionary computing techniques.
- Solving Puzzles: Like the Tower of Hanoi and the Chinese Ring puzzle.
- Circuit Design: Minimizes power consumption and glitches in state machines.
Binary To Gray Code OR Gray Code To Binary

Our Binary to Gray Code Converter webpage allows users to convert binary numbers to Gray code and vice versa through a toggle switch that changes the conversion mode. Users can input a binary number (or Gray code when in reverse mode) in the text field, click the "Convert" button to perform the conversion, or generate random binary input using the "Random Binary" button. This tool displays the conversion output with a copy-to-clipboard feature, provides a visual bit representation of the transformation, and shows step-by-step explanations of how each conversion is performed.
Binary To Gray Code Examples
101 (binary) = 111 (Gray code)
1010 (binary) = 1111 (Gray code)
1111 (binary) = 1000 (Gray code)
10000 (binary) = 11000 (Gray code)
10101 (binary) = 11101 (Gray code)
11110 (binary) = 10001 (Gray code)
100000 (binary) = 110000 (Gray code)
101010 (binary) = 111011 (Gray code)
1000000 (binary) = 1100000 (Gray code)
11111111 (binary) = 10000000 (Gray code)