我在这里真的很沮丧。尝试实现 CRC-CCITT 算法,我在 Internet 站点上找到了一个非常好的示例。
有一行我完全不明白其输出:
unsigned short update_crc_ccitt( unsigned short crc, char c){
[...]
short_c = 0x00ff & (unsigned short) c;
[...]
}
我想计算"test"
字符串的 CRC "123456789"
。所以在第一次运行中 char 'c' 是 1。根据我的理解short_c
,第一次运行应该也等于1
,但是当我将它打印到控制台时,我得到short_c = 49
了c = 1
. 如何?
0x00ff in binary is: 1 1 1 1 1 1 1 1
char 1 in binary is: 0 0 0 0 0 0 0 1
bitand should be : 0 0 0 0 0 0 0 1
我的错误在哪里?