Binary Gray Code Converter
Convert between binary and Gray code. This tool translates standard binary to reflected binary code (Gray code) and vice versa. Used in digital communications, encoders, and Karnaugh maps.
Binary to Gray Code Reference Table
| Decimal | Binary | Gray Code |
|---|---|---|
| 0 | 0000 | 0000 |
| 1 | 0001 | 0001 |
| 2 | 0010 | 0011 |
| 3 | 0011 | 0010 |
| 4 | 0100 | 0110 |
| 5 | 0101 | 0111 |
| 6 | 0110 | 0101 |
| 7 | 0111 | 0100 |
| 8 | 1000 | 1100 |
| 9 | 1001 | 1101 |
| 10 | 1010 | 1111 |
| 11 | 1011 | 1110 |
| 12 | 1100 | 1010 |
| 13 | 1101 | 1011 |
| 14 | 1110 | 1001 |
| 15 | 1111 | 1000 |
About Gray Code
Gray code (reflected binary code) is a binary numeral system where two consecutive values differ in only one bit position. This property makes it useful in digital communications, rotary encoders, and Karnaugh maps for minimizing errors during transitions.
Conversion: The MSB stays the same. Each subsequent bit is the XOR of the current and previous bit in the original number.
How It Works
This binary Gray code converter transforms between standard binary and Gray code (reflected binary code). Gray code ensures that consecutive values differ by only one bit, which is useful in many digital applications.
The conversion process:
- Binary to Gray: MSB stays the same. Each other bit = current binary bit XOR previous binary bit.
- Gray to Binary: MSB stays the same. Each other bit = current Gray bit XOR previous binary bit.
- XOR operation: The exclusive-OR operation is the key to both conversions.
- Step-by-step display: Shows each XOR operation for educational clarity.
For example: Binary 1011 → Gray 1110. Binary 0100 → Gray 0110. Notice consecutive Gray codes (0→1→2→3: 00→01→11→10) change only one bit at a time.
When You'd Actually Use This
Rotary Encoder Systems
Work with Gray code encoders that output position in Gray code to prevent reading errors during transitions.
Digital Communications
Use Gray code in modulation schemes (like QAM) to minimize bit errors from symbol misreading.
Karnaugh Map Design
Arrange K-maps using Gray code ordering so adjacent cells differ by one variable.
Error Minimization
Reduce errors in systems where values change incrementally and reading during transition matters.
Learning Digital Logic
Understand alternative binary encodings and their applications in digital systems.
CTF Challenges
Solve puzzles involving Gray code encoding and decoding in cybersecurity competitions.
What to Know Before Using
Gray code isn't for arithmetic
Don't try to add or multiply Gray codes directly. Convert to binary first, do math, convert back.
Multiple Gray code variants exist
This tool uses standard (reflected) Gray code. Other variants exist for specialized applications.
MSB is always the same
The leftmost bit doesn't change in conversion. It's the starting point for both algorithms.
Bit width must be consistent
Use the same number of bits for input and output. 4-bit binary converts to 4-bit Gray code.
Gray code wraps around
The last and first Gray codes also differ by one bit. This cyclic property is useful in some applications.
Common Questions
Why is it called Gray code?
Named after Frank Gray, a Bell Labs researcher who patented the reflected binary code in 1953 for shaft encoder applications.
What's the main advantage of Gray code?
Consecutive values differ by exactly one bit. This prevents errors when reading values during transitions - you get either the old or new value, never garbage.
How do rotary encoders use Gray code?
As the shaft rotates, the output changes one bit at a time. Even if read mid-transition, you get a valid adjacent value, not a random number.
What's the Gray code sequence for 0-15?
0000, 0001, 0011, 0010, 0110, 0111, 0101, 0100, 1100, 1101, 1111, 1110, 1010, 1011, 1001, 1000. Notice each changes one bit.
Can I do math directly in Gray code?
Not practically. Convert to binary, do arithmetic, convert back. Gray code is for representation and transmission, not computation.
Where else is Gray code used?
Digital TV (QAM modulation), genetic algorithms, Karnaugh maps, analog-to-digital converters, and anywhere single-bit transitions matter.
What's the XOR formula for conversion?
Binary to Gray: G[i] = B[i] XOR B[i+1]. Gray to Binary: B[i] = B[i+1] XOR G[i]. Work from MSB to LSB.
Other Free Tools
Binary Bit Flipper & Manipulator
Binary Bit Flipper & Manipulator
Binary to Hexadecimal Converter
Binary to Hexadecimal Converter
Decimal to Binary Converter
Decimal to Binary Converter
Binary to Octal Converter
Binary to Octal Converter
Binary to Decimal Converter
Binary to Decimal Converter
ASCII to Hex Converter
ASCII to Hex Converter: Text to Hexadecimal Translator
Free Printable Calendar Maker
Create & Print Your Custom Calendar
HTML Minifier
Free HTML Minifier & Compressor
Unix Timestamp Converter
Unix Timestamp Converter
Password Generator
Free Strong Password Generator