整形与格雷码互转

原文链接: http://www.cnblogs.com/luckytimor/p/7290469.html

整形转格雷码

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<>(1<

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<sizeof(x)*8;i++)  {  x^=x>>(1<return x;  }

转载于:https://www.cnblogs.com/luckytimor/p/7290469.html

你可能感兴趣的:(整形与格雷码互转)