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.
Interactive tool
Convert Binary to Gray Code
Ready
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.
| Input | Output | Meaning |
|---|---|---|
0 | 0 | zero boundary |
1 | 1 | one boundary |
1010 | 1111 | exact conversion |
0010 | 0011 | exact 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
Continue with related data converters
Choose the exact conversion direction you need.