function y = GrayDecoding(x,Nbits); % y = GrayDecoding(x,Nbits); % % returns 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) x = x - 2^(i-1); end; if (A~=dummy), y = y+2^(i-1); end; dummy = A; end;