examples

Toy examples in single C files.
git clone git://henryandlizzy.uk/examples
Log | Files | Refs

crc-table.c (489B)


      1 #include <stdio.h>
      2 
      3 unsigned crc_manual(unsigned poly, unsigned crc)
      4 {
      5 	for (unsigned j = 8; j; --j)
      6 		crc = (crc & 1) * poly ^ crc >> 1;
      7 
      8 	return crc;
      9 }
     10 
     11 int main()
     12 {
     13 	unsigned poly = 0x89;
     14 #if 0
     15 	for (unsigned i = 0; i <= 0xFF; ++i)
     16 		printf("[%2u] 0x%02x\n", i, crc_manual(poly, i));
     17 #else
     18 
     19 	for (unsigned i = 0; i < 0x10; ++i)
     20 		printf("A[%2u] 0x%02x\n", i, crc_manual(poly, i));
     21 
     22 	for (unsigned i = 0; i < 0x10; ++i)
     23 		printf("B[%2u] 0x%02x\n", i, crc_manual(poly, i << 4));
     24 #endif
     25 }