CSDN博客

img starhe

二进制格雷码与传统的连续二进制

发表于2004/6/29 11:44:00  469人阅读

——————————————————————————————————————

格雷码                                           连续码
——————————————————————————————————————

000                                               000
001                                               001
011                                               010
010                                               011
110                                               100
111                                               101
101                                               110
100                                               111
——————————————————————————————————————
转换:
unsigned int bin_to_Gray(unsigned int n)
{
     return n^(n>>1);
}
unsigned int Gray_to_bin(unsigned int n)
{
     int i;
     for(i=o;(1<<i)<sizeof(n) * CHAR_BIT;i++)
     {
           n^=n>>(1<<i);
     }
     return n;
}
0 0

相关博文

我的热门文章

img
取 消
img