You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
805 B
29 lines
805 B
namespace FBeeService
|
|
{
|
|
public static class Crc16
|
|
{
|
|
public static byte[] ComputeChecksum(byte[] crcbuf)
|
|
{
|
|
int crc = 0xffff;
|
|
int len = crcbuf.Length;
|
|
for (int n = 0; n < len; n++)
|
|
{
|
|
byte i;
|
|
crc = crc ^ crcbuf[n];
|
|
for (i = 0; i < 8; i++)
|
|
{
|
|
int TT;
|
|
TT = crc & 1;
|
|
crc = crc >> 1;
|
|
crc = crc & 0x7fff;
|
|
if (TT == 1)
|
|
{
|
|
crc = crc ^ 0xa001;
|
|
}
|
|
crc = crc & 0xffff;
|
|
}
|
|
}
|
|
return new byte[] { (byte)((crc >> 8) & 0xff), (byte)((crc & 0xff)) };
|
|
}
|
|
}
|
|
} |