Binary to Gray Code Converter
Convert binary to Gray code and back with MiniWebtool’s Binary to Gray Code Converter, including a step-by-step XOR walkthrough, truth table, and bit-by-bit visualization.
For Gemini, paste the copied question into the chat. You can also copy it below.Need help using this tool? Ask AI
View the question
Enter a binary number below and press Convert Binary to Gray Code to get the Gray code, with the XOR steps.
Video Guide: Binary to Gray Code Converter
About Binary to Gray Code Converter
Welcome to our Binary to Gray Code Converter, a free online tool that converts standard binary numbers into Gray code (reflected binary code). This converter shows the XOR rule, a clear bit-by-bit diagram, and a step-by-step breakdown so you can understand how the conversion works.
At a Glance
Binary to Gray Code Converter changes a binary number into reflected binary (Gray) code using Gray = Binary XOR (Binary >> 1). It shows an XOR truth table, a bit-by-bit diagram and step-by-step details.
| Feature | What you get | Good for |
|---|---|---|
| Conversion rule | Applies Gray = Binary XOR (Binary shifted right by 1). The top Gray bit equals the top binary bit. | Learning how reflected binary code is built |
| Input format | Enter 0s and 1s with an optional 0b prefix. Leading zeros and long bit strings are supported. | Pasting bit strings copied from code |
| XOR truth table | A truth table for XOR is shown above the input form. | Reviewing what XOR does before converting |
| Shift-and-XOR diagram | A diagram shows the binary row, the shifted row and the XOR result for each bit. | Verifying each output bit by hand |
| Decimal reference | The Gray bits read as an ordinary binary number are shown as a decimal reference value. | Seeing that Gray code changes the pattern, not the value |
What is Gray Code?
Gray code, also called reflected binary code, is a binary numeral system where two successive values differ in only one bit. This is useful in rotary encoders, digital communications, and other systems where multiple changing bits can cause errors during transitions.
How to Convert Binary to Gray Code
A common formula is:
- Gray = Binary XOR (Binary shifted right by 1)
In bit form, the most significant Gray bit equals the most significant binary bit. Every next Gray bit is the XOR of two adjacent binary bits.
This conversion changes the bit pattern (the code), not the underlying integer value represented by the original binary input.
How to Use This Converter (HowTo)
- Enter your binary number using only 0 and 1 (optional prefix: 0b).
- Click the convert button.
- Review the output Gray code, then scroll to see the shift-and-XOR diagram and the step-by-step details.
The diagram below shows how the formula works on a short example.
Example: Binary 1011 to Gray code
Understanding XOR
XOR (exclusive OR) outputs 1 when the two input bits are different, and 0 when they are the same. The XOR truth table is shown above the input form on this page.
Where Gray Code is Used
- Rotary encoders: reduces misreads when moving between positions
- Digital electronics: avoids glitches when multiple bits change at once
- Error-sensitive transitions: helps minimize transient state ambiguity
FAQ
What is Gray code?
Gray code is a binary numeral system where consecutive values differ by exactly one bit. This property helps reduce errors during transitions in real-world devices such as rotary encoders.
How do you convert binary to Gray code?
You can compute Gray code by XORing the binary number with the same number shifted right by one bit: Gray = Binary XOR (Binary >> 1). This tool shows the shift row and the XOR result row so you can verify each bit.
Does Gray code represent the same decimal value as the input?
Gray code is a different encoding of the same sequence index, not a different base. If you interpret the Gray bits as a normal binary number, you usually get a different decimal value. That is why this page shows the Gray bits interpreted as binary only as a reference.
Can I convert Gray code back to binary?
Yes. Use our Gray Code to Binary Converter. The reverse conversion can also be done bit by bit using XOR with the previously recovered binary bit.
Additional Resources
Reference this content, page, or tool as:
"Binary to Gray Code Converter" at https://MiniWebtool.com/binary-to-gray-code-converter/ from MiniWebtool, https://MiniWebtool.com/
by miniwebtool team. Updated: October 28, 2026
Chat with your favorite AI
For Gemini, paste the copied question into the chat. You can also copy it below.
View the question
Number System Converters:
- Binary to Gray Code Converter Popular
- BCD Converter Popular