Decimal to Gray Code Converter – Free Online Tool

Decimal to Gray Code Converter

This decimal to gray code converter instantly converts any decimal number to its Gray code equivalent — and decodes Gray code back to decimal. Get the binary, Gray code, and hex values all at once, free and private in your browser.

🔢 Decimal → Gray Code
⬅ Gray Code → Decimal
Decimal Input DEC
Enter any non-negative decimal integer
Gray Code Output GRAY
Result appears here
Full Conversion Breakdown
Decimal
Binary
Gray Code
Hexadecimal
Gray Code Table Generator
From To
Decimal Binary Gray Code Hex

Decimal to Gray Code Converter: Convert Any Number Instantly Free

Decimal to gray code converter is a free online tool that converts any decimal number to its Gray code equivalent instantly — and decodes Gray code back to decimal as well. Along with the Gray code result, this tool also shows the binary representation and hexadecimal value so you get a complete picture in one step. Whether you are a student studying digital electronics, an engineer working with rotary encoders, or a developer debugging a digital system, this tool gives you an accurate result without manual calculation.

What Is Gray Code?

Gray code, formally known as reflected binary code, is a binary numeral system in which two consecutive values always differ by exactly one bit. This single-bit-change property sets it apart from standard binary, where transitioning between some numbers requires multiple bits to change simultaneously.

For example, converting from decimal 3 (binary 011) to decimal 4 (binary 100) in standard binary requires all three bits to change at once. In Gray code, however, 3 is represented as 010 and 4 as 110 — only one bit changes. This seemingly small difference has significant practical consequences in hardware design and signal processing.

Why Is Gray Code Used?

Gray code was originally designed to prevent spurious output from electromechanical switches, but its applications have expanded considerably since then. Today it is used in several important areas of engineering and computing.

Gray Code in Rotary Encoders

Rotary encoders — devices that convert angular position into a digital signal — commonly use Gray code to represent position values. Because mechanical and optical sensors read each bit at a slightly different moment, using standard binary can produce incorrect intermediate readings during transitions when multiple bits change simultaneously. Gray code eliminates this problem entirely since only one bit ever changes between adjacent positions. As a result, encoders using Gray code produce reliable, error-free position readings even during rapid rotation.

Gray Code in Digital Circuits

In digital logic design, Gray code is used in Karnaugh maps (K-maps), which are a graphical method for simplifying Boolean expressions. The values in a K-map are arranged in Gray code order so that adjacent cells differ by only one variable, making it easier to identify groups and minimize logic expressions correctly. Understanding the relationship between decimal values and their Gray code equivalents is therefore a fundamental skill in digital electronics coursework.

Gray Code in Error Detection

The single-bit-change property of Gray code also makes it useful in certain error detection schemes. Because transitions between consecutive values change only one bit, any reading that differs from an expected value by more than one bit is immediately identifiable as an error, which simplifies fault detection in some systems.

How to Convert Decimal to Gray Code

There are two equivalent methods for converting a decimal number to Gray code. This tool applies the bitwise method automatically, but understanding the manual method helps you verify results and build intuition for how the conversion works.

Manual Method: Step by Step

First, convert the decimal number to standard binary. Then, copy the most significant (leftmost) bit of the binary number directly as the first bit of the Gray code. For each subsequent bit position, XOR the current binary bit with the previous binary bit to get the corresponding Gray code bit. The XOR operation produces 0 when both bits are the same and 1 when they differ.

For example, to convert decimal 13 to Gray code: 13 in binary is 1101. The first Gray code bit is 1 (same as binary). The second bit is 1 XOR 1 = 0. The third bit is 1 XOR 0 = 1. The fourth bit is 0 XOR 1 = 1. The result is 1011.

Bitwise Formula Method

The faster method uses a single formula: Gray = N XOR (N shifted right by 1 bit). For decimal 13, this means 1101 XOR 0110 = 1011, which matches the manual result. This formula is what programming languages and digital circuits use to perform the conversion efficiently.

How to Decode Gray Code to Decimal

Decoding Gray code back to decimal is slightly different from encoding. The most significant bit of the binary output is the same as the most significant bit of the Gray code. For each subsequent bit, XOR the previous binary bit with the current Gray code bit to get the next binary bit. Once all binary bits are determined, convert the binary number to decimal normally.

This tool handles the full decoding process automatically. Simply switch to “Gray Code → Decimal” mode, enter your Gray code string using only 0s and 1s, and click the button to see the decimal result along with the binary and hexadecimal values.

Gray Code Table: Decimal 0 to 15

The table at the bottom of the tool generates a Gray code reference table for any range of decimal values from 0 to 255. The default view shows decimal 0 through 15, which covers the standard 4-bit Gray code sequence used in most textbook examples and K-map exercises. You can change the range by entering new From and To values and clicking Generate Table.

The table shows the decimal value, its standard binary representation, the corresponding Gray code, and the hexadecimal equivalent — all four representations side by side for easy reference.

Full Conversion Breakdown

After each conversion, the tool shows a complete breakdown panel with four values simultaneously: the decimal number, the binary representation, the Gray code output, and the hexadecimal equivalent. This is useful when you need all four representations for a report, assignment, or system specification, since it eliminates the need to run multiple separate conversions.

Copy buttons below the result panel let you copy the Gray code, binary, or decimal value individually to your clipboard with one click.

Working with hexadecimal values alongside your Gray code
conversions? Use our Hex Encoder and Decoder to convert hex strings instantly in your browser.

Frequently Asked Questions

Q: How do I convert decimal to Gray code online?

Select the “Decimal → Gray Code” mode, enter your decimal number in the input field, and click Convert to Gray Code. The tool shows the Gray code result instantly along with the binary and hexadecimal values in the breakdown panel below.

Q: What is the Gray code for decimal 13?

Decimal 13 in binary is 1101. Applying the Gray code conversion gives 1011. You can verify this using the tool by entering 13 in decimal mode and clicking Convert.

Q: How do I decode Gray code back to decimal?

Switch to the “Gray Code → Decimal” mode using the mode button at the top. Enter your Gray code string using only 0s and 1s, then click Decode to Decimal. The tool converts the Gray code to decimal and also shows the binary and hexadecimal equivalents.

Q: What is the difference between binary and Gray code?

In standard binary, consecutive numbers can differ by multiple bits simultaneously. In Gray code, consecutive numbers always differ by exactly one bit. This single-bit-change property makes Gray code more reliable in hardware applications where simultaneous bit transitions can cause reading errors.

Q: Why does only one bit change between consecutive Gray code values?

This is the defining property of Gray code, achieved by the XOR-based conversion formula. Each Gray code value is derived by XORing the binary representation with itself shifted right by one bit, which mathematically guarantees that adjacent values in the sequence always differ by exactly one bit position.

Q: What is the largest number this converter supports?

The converter supports decimal values up to 4,294,967,295, which is the maximum value for a 32-bit unsigned integer. The Gray code table generator supports values from 0 to 255 for practical reference table use.

Q: Is my data sent to a server when I use this tool?

No. All conversions happen entirely inside your browser using JavaScript. Nothing you enter is sent to any server or stored anywhere. The tool works fully offline once the page has loaded.

Conclusion

Gray code is a fundamental concept in digital electronics, embedded systems, and computer engineering, and converting between decimal and Gray code manually is a time-consuming process that is easy to get wrong.

This free decimal to gray code converter handles the conversion in both directions instantly, shows the complete breakdown with binary and hexadecimal values alongside the result, and generates reference tables for any range of values up to 255.

Everything runs privately in your browser with no data sent anywhere. Enter your decimal number or Gray code string, click the button, and get an accurate result immediately.