function y = GrayCoding(x,Nbits); % y = GrayCoding(x,Nbits); % % reverses the systematic Gray code of the Nbit number x. % S Weiss, 10/10/2000 % x in [0; 2^Nbits-1] y = 0; dummy = 0; for i = Nbits:-1:1, A = floor(x/2^(i-1)); if (A==1) % i-th bit is set x = x - 2^(i-1); end; if (A~=dummy), y = y+2^(i-1); dummy = 1; else dummy = 0; end; end;