#include /* * Generates 8-bit CRC calculation table * * Author: R.J. van der Putten, Leiden, Holland, * rob at sput dot nl. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ int main(void) { int i, j; unsigned int r; /* * 8 bits CRC * * 0000 xxxx xxxx * 0000 1111 1111 * 0 F F * 0001 0000 0000 * 1 0 0 * */ unsigned int poly = 0x31; printf("/* 8-bit CRC calculation table */\n\n"); printf("unsigned int crctab[] = { \\\n\t"); for (i = 0; i < 256; i++) { r = i; for (j = 0; j < 8; j++) { if ((r & 0x80) != 0) { /* xxxx 1xxx xxxx */ r = (r << 1) ^ poly; } else { r = r << 1; } r = r & 0xFF; } if (i != 0) { if ((i % 4) == 0) printf("\n\t"); else printf(" "); } printf("0x%04X", r); if(i != 255) printf(","); } printf("\n};\n"); return(0); }