Skip to content

Instantly share code, notes, and snippets.

@oilking143
Created April 17, 2016 05:46
Show Gist options
  • Save oilking143/9e9b21bf32c097f79f7f4be1af381da3 to your computer and use it in GitHub Desktop.
Save oilking143/9e9b21bf32c097f79f7f4be1af381da3 to your computer and use it in GitHub Desktop.
private int Calculate_CRC16(byte[] buff, int len)
{
int u16CRC;
u16CRC = 0xFFFF;
for(int i=0; i<len; i++)
{
u16CRC = ((u16CRC>>8) | (u16CRC<<8))&0xFFFF;
u16CRC ^= (buff[i]&0xFF);
u16CRC ^= ((u16CRC&0xFF)>>4);
u16CRC ^= (u16CRC<<12)&0xFFFF;
u16CRC ^= ((u16CRC&0xFF)<<5)&0xFFFF;
}
u16CRC &= 0xFFFF;
return u16CRC;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment