晕了,懂C++的人进

handsomge handsomge 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
高人请将该算法转化成 C#,多谢! 我是晕了。

赫赫,不限手法,只要结果正确。

struct B
{
unsigned char lo;
unsigned char hi;
};
union w2b
{
unsigned short w;
struct B b;
};
union s2b
{
signed short w;
struct B b;
};
unsigned short CRC16(unsigned char *buf, unsigned char len)
{
union w2b CRC16;
unsigned char i,j;
unsigned short poly = 0xa001;

CRC16.w = 0xffff;
while(len--)
{
CRC16.b.lo ^= *buf++;
for (i = 0; i < 8; i++)
{
j = CRC16.b.lo & 0x01;
CRC16.w >>= 1;
if (j) CRC16.w ^= poly;
};
};
return CRC16.w;
}
...全文
评论 16
收藏 已收藏
分享
返回顶部
handsomge
C# 111,129 成员 642,538 内容