【发布时间】:2013-09-10 05:24:18
【问题描述】:
我真的很沮丧。尝试实现 CRC-CCITT 算法,我在 Internet 站点上找到了一个非常好的示例。
有一行我完全不明白的输出:
unsigned short update_crc_ccitt( unsigned short crc, char c){
[...]
short_c = 0x00ff & (unsigned short) c;
[...]
}
我想计算"test" 字符串"123456789" 的CRC。所以在第一次运行中 char 'c' 是 1。根据我的理解,第一次运行的 short_c 也应该等于 1,但是当我将它打印到控制台时,我得到 short_c = 49 for @987654327 @。怎么样?
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
我的错误在哪里?
【问题讨论】:
-
'1'是一个字符(即在字符串中),只是1是数字,"1"是一个字符串,都是不同的。 -
是的,我现在可以看到了。我正在尝试将 C 代码传输到 matlab,所以除了成为 C 菜鸟之外,这对我来说是一个额外的困难。
标签: c char hex bitwise-and