Created
December 10, 2017 08:39
-
-
Save gamaral/40418155dc615f4df42e70c0008d820d to your computer and use it in GitHub Desktop.
CRC-8 for J1850
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
uint8_t | |
calculate_crc(const uint8_t *data, const size_t n) | |
{ | |
const uint8_t poly = 0b00011101; | |
int datai, biti; | |
uint8_t crc = ~0; | |
for (datai = 0; datai < n; ++datai, ++data) { | |
crc ^= *data; | |
for (biti = 0; biti < 8; ++biti) | |
crc = (crc << 1) ^ (crc & 0x80 ? poly : 0); | |
} | |
return ~crc; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment