Gray Code Converter
Convert between binary and the reflected binary (Gray) code, generate the n-bit Gray-code sequence, and inspect the single-bit-transition property that makes Gray codes useful for rotary encoders and Karnaugh-map axes. Enter a decimal number, a binary string, or a Gray string and get the conversions at once. Everything runs locally in your browser.
n-bit Gray-code sequence (index → Gray → binary)
Gray code (reflected binary) orders the 2ⁿ values so that successive values differ in exactly one bit — unlike plain binary, where e.g. 3→4 (011→100) flips three bits. Binary → Gray: keep the most-significant bit, then each Gray bit g[i] = b[i] XOR b[i−1] — equivalently g = b XOR (b >> 1). Gray → binary: the MSB is unchanged, then b[i] = g[i] XOR b[i−1]. The sequence is built by reflection: the n-bit list is the (n−1)-bit list, a copy in reverse with a leading 1 prefixed. Gray codes power rotary shaft encoders (no ambiguous multi-bit transitions at boundaries) and the axes of Karnaugh maps (adjacent cells differ in one variable). Pairs with the Quine-McCluskey minimizer and Hamming code tools. Everything runs locally — nothing leaves your browser.