Function GraycodeN with
parameter N indicating the
number of inputs transforms Boolean number K (in the range 0..2^{N}-1) into the K^{th}
pattern in the Gray code. If the circuit for such function is run in
reverse, the output is the ordinal number of the corresponding Gray
code pattern. Assuming GraycodeN
function has inputs/outputs labeled a_{},b,...,z , its optimal circuit is TOF(b_{};a_{})
TOF(c;b) ... TOF(z;y_{}).

For example, circuit for Graycode6
is illustrated below.