Created
July 6, 2014 16:36
-
-
Save aurelj/270bb8af82f65fa645c1 to your computer and use it in GitHub Desktop.
Simple CRC-16-MCRF4XX C implementation.
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
#include <stdint.h> | |
#include <stddef.h> | |
uint16_t crc16_mcrf4xx(uint16_t crc, uint8_t *data, size_t len) | |
{ | |
if (!data || len < 0) | |
return crc; | |
while (len--) { | |
crc ^= *data++; | |
for (int i=0; i<8; i++) { | |
if (crc & 1) crc = (crc >> 1) ^ 0x8408; | |
else crc = (crc >> 1); | |
} | |
} | |
return crc; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The initial implementation and the one by @mudgek1 produce different results for some numbers (e.g. 0x76). Which one is correct?