Skip to content

Instantly share code, notes, and snippets.

@cdesch
Created March 1, 2012 19:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdesch/1952416 to your computer and use it in GitHub Desktop.
Save cdesch/1952416 to your computer and use it in GitHub Desktop.
CRC8
//
// CRC8.m
//
// Created by Chris Desch on 2/6/12.
// Translation from http://avrhelp.mcselec.com/index.html?crc8.htm
- (int)crc8Checksum:(NSString*)dataFrame{
char j;
int crc8 = 0;
int x = 0;
for (int i = 0; i < [dataFrame length]; i++){
x = [dataFrame characterAtIndex:i];
for (int k = 0; k < 8; k++){
j = 1 & (x ^ crc8);
crc8 = floor0(crc8 / 2) & 0xFF;
x = floor0(x / 2) & 0xFF;
if (j != 0 ){
crc8 = crc8 ^ 0x8C;
}
}
}
return crc8;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment