Created
March 1, 2012 19:14
-
-
Save cdesch/1952416 to your computer and use it in GitHub Desktop.
CRC8
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
// | |
// 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