#include /* * Generates CCITT 16-bit CRC calculation table * * Copyright (c) 2022 - 2023 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; unsigned int poly = 0x1021; printf("/* CCITT 16-bit CRC calculation table */\n\n"); printf("unsigned int crctab[] = { \\\n\t"); for (i = 0; i < 256; i++) { /* CRC Width - 8 */ r = i << 8; for (j = 0; j < 8; j++) { if ((r & 0x8000) != 0) { /* 1xxx xxxx xxxx xxxx */ r = (r << 1) ^ poly; } else { r = r << 1; } r = r & 0xFFFF; } if (i != 0) { if ((i % 4) == 0) printf("\n\t"); else printf(" "); } printf("0x%04X", r); if(i != 255) printf(","); } printf("\n};\n\n"); return(0); }