TOP

Free browser converter

Decimal to Gray Code Converter

Convert a non-negative decimal integer to reflected binary Gray code with exact BigInt arithmetic and an optional four-bit display width.

No signupFree online conversion

Interactive tool

Convert decimal integers to Gray code

Ready

Mode and output format

Choose the exact data representation; the tool never guesses an encoding.

Detailed conversion guide

How to Convert Decimal to Gray Code

First express the decimal integer as binary. Then XOR that binary value with itself shifted right by one bit: gray = n XOR (n >> 1).

Decimal 10 is binary 1010. Shifting gives 0101, and 1010 XOR 0101 produces Gray code 1111. Adjacent Gray values differ by one bit.

InputOutputMeaning
00zero
11one bit
1011111010 XOR 0101
1510001111 XOR 0111

Decimal to Gray Code with BigInt

BigInt preserves integers above JavaScript's safe Number limit. The XOR formula is exact and does not use floating-point arithmetic.

const value = BigInt(decimal);
const gray = value ^ (value >> 1n);
const bits = gray.toString(2);

Whole Numbers, Width, and Leading Zeros

This converter accepts non-negative whole numbers only. Negative values, fractions, exponential notation, commas, and prose are rejected.

Minimal width omits unnecessary leading zeros. Four-bit padding changes only presentation; it does not change the Gray code magnitude.

Related converters

Choose the converter for the exact direction and representation you need.

Advertisement

Sponsored link