Created
May 12, 2016 19:26
-
-
Save jeancroy/50e8d02314ad45309411d9faf9473eb2 to your computer and use it in GitHub Desktop.
This file contains 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
private ulong CalculateCRCdirect(byte[] data, int length) | |
{ | |
// Initialize all variables for seeding and builing based upon the given coding type | |
// at first, compute constant bit masks for whole CRC and CRC high bit | |
crcmask = ((((ulong)1 << (order - 1)) - 1) << 1) | 1; //ORDER = 5 | |
crchighbit = (ulong)1 << (order - 1); | |
poly = 0x09 // CRC5 EPC | |
ulong c, bit; | |
ulong crc = 0x09 | |
for (int i = 0; i < length; i++) | |
{ | |
c = (ulong)data[i]; | |
for (ulong j = 0x80; j > 0; j >>= 1) | |
{ | |
bit = crc & crchighbit; | |
crc <<= 1; | |
if ((c & j) > 0) bit ^= crchighbit; | |
if (bit > 0) crc ^= poly; | |
} | |
} | |
crc &= crcmask; | |
return crc; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment