Skip to content

Instantly share code, notes, and snippets.

@nazrdogan
Created August 21, 2013 13:44
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 nazrdogan/6294629 to your computer and use it in GitHub Desktop.
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.
#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