110,538
社区成员
发帖
与我相关
我的任务
分享
unsigned char RedGetFc(char *pack,unsigned int len)
{
#define CRCNUM 0xa001
unsigned char test,crclow,crchigh,recode;
unsigned int i,j,crcnum=0xffff,t;
if(len==0)
return(-1);
for(i=1;i<=len;i++)
{
test=*pack;
crclow=(char)crcnum;
crchigh=(char)(crcnum>>8);
crcnum=(unsighed int)(test^crclow)+((unsighed int)crchigh)*256;
for(j=1;j<=8;j++)
{
t=crcnum&0x0001;
crcnum=crcnum>>1;
if(t)
{
crcnum=crcnum^CRCNUM;
}
}
pack++;
}
recode=(unsighed char)crcnum;
return(recode);
}
byte RedGetFc(string pack, uint len)
{
const ushort CRCNUM = 0xa001;
byte test, crclow, crchigh, recode;
uint j, crcnum = 0xffff, t;
if (len == 0) return 0xFF;
for (int i = 1; i <= len; i++)
{
test = (byte)pack[i - 1];
crclow = (byte)crcnum;
crchigh = (byte)(crcnum >> 8);
crcnum = (uint)(test ^ crclow) + ((uint)crchigh) * 256;
for (j = 1; j <= 8; j++)
{
t = crcnum & 0x0001;
crcnum = crcnum >> 1;
if (t != 0)
{
crcnum = crcnum ^ CRCNUM;
}
}
}
recode = (byte)crcnum;
return (recode);
}
byte[] rebuf = BitConverter.GetBytes(crcnum);
string Re = Convert.ToBase64String(rebuf);