UnChar A_crc(UnChar str[],UnChar count)
{
UnChar i,j,m,n;
UnChar CRC;
//CRC=0;
for(j=0;j<count;j++)
{
m=str[j];
n=str[j];
for(i=0;i<8;i++)
{
m^=CRC;
if(m&0x01)
{ CRC=((CRC^0x18)>>1)|0x80;}
else
{ CRC=CRC>>1;}
m=n>>1;
n=m;
}
}
return CRC;
}
{
UnChar i,j,m,n;
UnChar CRC;
//CRC=0;
for(j=0;j<count;j++)
{
m=str[j];
n=str[j];
for(i=0;i<8;i++)
{
m^=CRC;
if(m&0x01)
{ CRC=((CRC^0x18)>>1)|0x80;}
else
{ CRC=CRC>>1;}
m=n>>1;
n=m;
}
}
return CRC;
}
{
int i, j, m, n;
int CRC =0;
//CRC=0;
for (j = 0; j < str.Length; j++)
{
m = str[j];
n = str[j];
for (i = 0; i < 8; i++)
{
m ^= CRC;
if ((m & 0x01) != 0)
{ CRC = ((CRC ^ 0x18) >> 1) | 0x80; }
else
{ CRC = CRC >> 1; }
m = n >> 1;
n = m;
}
}
return (char)CRC;
}
不知道合不合要求
上面写的结果都不对,这是一个8位的CRC校验算法
------------------------------------------
private int A_int(string str)
{
string c;
int i, m, n;
int CRC = 0x00;
//CRC=0;
while ( str.Length>0 )
{
c = str.Substring(0,2);
str = str.Remove(0,2);
int intValue = Convert.ToInt32( c,16);
//string s = Convert.ToString(intValue,10);
//int int10 = int.Parse( Convert.ToString(intValue,10) ); m = intValue;
n = intValue;
for (i = 0; i < 8; i++)
{
m ^= CRC;
if ( (m&0x01) != 0 )
{
CRC = ((CRC ^ 0x18) >> 1) | 0x80;
}
else
{
CRC = CRC >> 1;
}
m = n >> 1;
n = m;
}
}
return CRC;
}