Bytelify

Decimal to Gray Code Converter

Convert decimal to Gray code (binary), live as you type.

Runs in your browser, nothing sent
decimal-to-grey-code
111111

Gray code is a binary numbering system where consecutive values differ by exactly one bit — used in rotary encoders and error correction to avoid glitches from multiple bits flipping at once. Converts live as you type, entirely in your browser.

Need the opposite? Gray Code to Decimal Converter

What is Decimal to Gray Code Converter?

Gray code is a binary numbering system where consecutive values differ by exactly one bit, used in rotary encoders, Karnaugh maps, and error correction to avoid glitches from multiple bits flipping at once during a transition. Type a decimal number and get its Gray code equivalent instantly, with optional bit-width padding so the output lines up at a fixed length across a batch of values. Multiple values are supported at once, which is useful when you're building a lookup table or verifying a sequence rather than converting one number at a time. Conversion happens live as you type, entirely in your browser. Nothing is sent to a server.

Decimal to Gray Code Chart (0-15)

DecimalGray Code
00000
10001
20011
30010
40110
50111
60101
70100
81100
91101
101111
111110
121010
131011
141001
151000

How to Use the Decimal to Gray Code Converter

  1. 1

    Enter a Decimal Number: Type one or more non-negative whole numbers, for example 12 or 25.

  2. 2

    Set a Bit Width (Optional): Pad the output to a fixed number of bits if you need every result to line up for a lookup table.

  3. 3

    Read the Gray Code Result Instantly: The Gray code equivalent appears automatically, with no button to click.

  4. 4

    Copy the Result: Use the copy button to copy the Gray code value for use in hardware design, coursework, or documentation.

How Decimal Converts to Gray Code

First convert the decimal number to regular binary. Then, starting from the leftmost (most significant) bit, each Gray code bit is the XOR of that binary bit with the binary bit immediately to its left (the leftmost Gray bit is just copied from binary unchanged, since there's no bit to its left). The result is a code where every consecutive decimal value differs from the last by exactly one bit.

How to Convert Decimal to Gray Code

Converting 12: first, 12 in binary is 1100. Line the bits up and XOR each bit with the one before it. The first Gray bit (1) is copied as-is, then 1 XOR 1 = 0, 0 XOR 0 = 0, 0 XOR 0 = 0, giving Gray code 1010. As a check: 11 in Gray code is 1110, and 1010 (12) differs from 1110 (11) by exactly one bit (the second position), confirming the one-bit-change property.

Examples

OUTPUT
5 → binary 0101 → Gray code 0111
25 → binary 11001 → Gray code 10101
8 → binary 1000 → Gray code 1100
FAQs

Frequently Asked Questions

Common questions about Decimal to Gray Code Converter.

In regular binary, counting from 3 to 4 flips three bits (011 → 100). In Gray code, every increment flips exactly one bit, which avoids the ambiguous in-between states a mechanical or electrical sensor could otherwise read.

It pads every output value with leading zeros to a fixed number of bits, so a batch of Gray code values lines up consistently: useful when building a lookup table or feeding results into hardware with a fixed bus width.

Yes, enter multiple values and each is converted to its own Gray code output.

Common real-world uses include rotary and linear position encoders (so a sensor misreading mid-transition is off by at most one count instead of a wild jump), Karnaugh maps in digital logic design, and some error-correction and communication schemes.

It's named after physicist Frank Gray, who patented a reflected binary code method at Bell Labs in the 1940s for use in signal transmission, though related ideas existed earlier.

Yes, Bytelify's Decimal to Gray Code Converter is free with no account or sign-up required.

No. The conversion runs entirely client-side in your browser, so your numbers are never sent anywhere.