整形转格雷码
x= (x>>1)^x
格雷码转整形(3种方法)
static unsigned int GraytoDecimal(unsigned int x) { unsigned int y = x; while(x>>=1) y ^= x; return y; } static unsigned int GraytoDecimal(unsigned int x) { x^=x>>16; x^=x>>8; x^=x>>4; x^=X>>2; x^=x^1; return x; } static unsigned int GraytoDecimal(unsigned int x) { int i; for(i=0;(1<<i)<sizeof(x)*8;i++) { x^=x>>(1<<i); } return x; }
staticunsignedint GraytoDecimal(unsignedint x) { unsignedint y = x; while(x>>=1) y ^= x; return y; } staticunsignedint GraytoDecimal(unsignedint x) { x^=x>>16; x^=x>>8; x^=x>>4; x^=X>>2; x^=x^1; return x; } staticunsignedint GraytoDecimal(unsignedint x) { int i; for(i=0;(1<<i)<sizeof(x)*8;i++) { x^=x>>(1<<i); } return x; }