wfdavis@davis-inc.com wrote: > With regard to algorithms, here are two schemes. b(i) and g(i) > refer to the i-th bit of the n-bit binary and Gray-code > representations, respectively. The symbol X stands for exclusive OR. > > Binary to Gray-code conversion: > > g(i) = b(i) X b(i+1) where i = 0,1,2,...n-1 > g(n) = b(n) Warren: This is wrong... Try it and you'll see. The CORRECT algorithm is g(i) = b(i) ^ (b(i) >> 1), where "^" means "xor" and ">> 1" means "right-shifted 1 bit". > Gray-code to binary conversion: > > b(n) = g(n) > b(i) = g(i) X b(i+1) where i = n-1,...2,1,0 This is also wrong, of course. -Andy === Andrew Warren - fastfwd@ix.netcom.com === === Fast Forward Engineering - Vista, California === === === === Did the information in this post help you? Consider === === contributing to the PICLIST Fund. Details are at: === === http://www.geocities.com/SiliconValley/2499/fund.html ===