A Gray code is an encoding of numbers so that adjacent numbers have a single digit differing by 1. The term Gray code is often used to refer to a "reflected" code, or more specifically still, the binary reflected Gray code. To convert a binary number d_1 d_2 ...d_(n - 1) d_n to its corresponding binary reflected Gray code, start at the right with the digit d_n (the nth, or last, digit). If the d_(n - 1) is 1, replace d_n by 1 - d_n; otherwise, leave it unchanged. Then proceed to d_(n - 1). Continue up to the first digit d_1, which is kept the same since d_0 is assumed to be a 0. The resulting number g_1 g_2 ...g_(n - 1) g_n is the reflected binary Gray code.