Created
August 21, 2013 13:44
-
-
Save nazrdogan/6294629 to your computer and use it in GitHub Desktop.
The FCS(Frame Check Sum)-16 generator polynomial: x**0 + x**5 + x**12 + x**16.
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
#define P 0x8408 | |
main() | |
{ | |
register unsigned int b, v; | |
register int i; | |
printf("typedef unsigned short u16;\n"); | |
printf("static u16 fcstab[256] = {"); | |
for (b = 0; ; ) | |
{ | |
if (b % 8 == 0) | |
printf("\n"); | |
v = b; | |
for (i = 8; i--; ) | |
v = v & 1 ? (v >> 1) ^ P : v >> 1; | |
printf("\t0x%04x", v & 0xFFFF); | |
if (++b == 256) | |
break; | |
printf(","); | |
} | |
printf("\n};\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment