Skip to content

Instantly share code, notes, and snippets.

@nofxx
Created August 2, 2017 00:36
Show Gist options
  • Save nofxx/8ae1afca35f09553e719ce03050a1651 to your computer and use it in GitHub Desktop.
Save nofxx/8ae1afca35f09553e719ce03050a1651 to your computer and use it in GitHub Desktop.
C++To ruby,...
def self.crc16(buf)
crc = 0xffff
buf.each_byte do |b|
crc = (crc >> 8) ^ CRC_LOOKUP[(crc ^ b) & 0xff]
end
~crc
end
U16 GetCrc16(const U8* pData, size_t nLength)
{
U16 fcs = 0xffff; // initialization
while(nLength>0){
fcs = (fcs >> 8) ^ crctab16[(fcs ^ *pData) & 0xff];
nLength--;
pData++;
}
return ~fcs; // negated
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment