如何将以下代码转换为C#。我的C有点生疏:
short CalcCrc(char *str,int len)
{
short crc=0;
for(int i=0;i<len;i++)
crc ^= (short)((unsigned char)str[i]) << (i%9);
return crc;
}
答案 0 :(得分:2)
short CalcCrc(string str)
{
short crc = 0;
for (int i = 0; i < str.Length; i++)
crc ^= (short)(str[i] << (i % 9));
return crc;
}