Created
August 2, 2017 00:36
-
-
Save nofxx/8ae1afca35f09553e719ce03050a1651 to your computer and use it in GitHub Desktop.
C++To ruby,...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def self.crc16(buf) | |
crc = 0xffff | |
buf.each_byte do |b| | |
crc = (crc >> 8) ^ CRC_LOOKUP[(crc ^ b) & 0xff] | |
end | |
~crc | |
end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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