TOP

Free browser converter

Binary to Gray Code Converter

Convert ordinary binary to reflected Gray code online with exact BigInt XOR, preserved bit width, strict binary validation, large-input support, and optional 0b output.

No signupFree online conversion

Interactive tool

Convert Binary to Gray Code

Ready

Output format

Choose an explicit output representation.

Detailed conversion guide

How to Convert Binary to Gray Code

Keep the most significant binary bit, then XOR each adjacent binary-bit pair. Numerically, gray = n XOR (n >> 1).

Binary 1010 shifted right is 0101. XOR produces reflected Gray code 1111, where adjacent encoded integers differ by one bit.

InputOutputMeaning
00zero boundary
11one boundary
10101111exact conversion
00100011exact conversion

Binary to Gray Code with BigInt

BigInt makes the XOR exact for long bit strings, while padStart preserves the validated input width.

const value = BigInt('0b' + binary);
const gray = value ^ (value >> 1n);
const bits = gray.toString(2).padStart(binary.length, '0');

Binary Input, Gray Output, and Width

This page expects ordinary binary, not decimal or an existing Gray code. Characters other than 0 and 1 are rejected.

Leading zeros are preserved because register width and hardware vectors may depend on them. A 0b prefix is optional output notation.

Related converters

Choose the exact conversion direction you need.

Advertisement

Sponsored link