Skip to content

Instantly share code, notes, and snippets.

@aurelj
Created July 6, 2014 16:36
Show Gist options
  • Select an option

  • Save aurelj/270bb8af82f65fa645c1 to your computer and use it in GitHub Desktop.

Select an option

Save aurelj/270bb8af82f65fa645c1 to your computer and use it in GitHub Desktop.
Simple CRC-16-MCRF4XX C implementation.
#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;
}
@maxfreu
Copy link
Copy Markdown

maxfreu commented Nov 10, 2023

The initial implementation and the one by @mudgek1 produce different results for some numbers (e.g. 0x76). Which one is correct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment