Cleanup
This commit is contained in:
parent
6703a07e0f
commit
56b996cfd5
@ -1,3 +1,7 @@
|
||||
# TinyCRC
|
||||
|
||||
This is a library for calculating CRC32, CRC16 and CRC8.
|
||||
This is a library for calculating CRC32, CRC16 and CRC8. I did not write these, but
|
||||
they are collected from various places on the interweb, and as such available under
|
||||
the MIT license.
|
||||
|
||||
The library should be portable enough to work on embedded systems.
|
12
crctest.cpp
12
crctest.cpp
@ -10,29 +10,31 @@ void test(const uint8_t* buffer)
|
||||
uint16_t crc16 = tinycrc_crc16(buffer, strlen((char*)buffer));
|
||||
uint8_t crc8 = tinycrc_crc8(buffer, strlen((char*)buffer));
|
||||
|
||||
printf("%-32s | crc32 | %08x\n", (char*)buffer, crc32);
|
||||
printf("%-32s | crc16 | %04x\n", (char*)buffer, crc16);
|
||||
printf("%-32s | crc8 | %02x\n", (char*)buffer, crc8);
|
||||
|
||||
printf("%-32s | %08x | %04x | %02x\n", (char*)buffer, crc32, crc16, crc8);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
uint8_t* buffer = (uint8_t*)malloc(32);
|
||||
|
||||
printf("%-32s | %8d | %4d | %2d\n", (char*)buffer, 32, 16, 8);
|
||||
|
||||
memset((char*)buffer, 0, 32);
|
||||
strcpy((char*)buffer, "Hello World\0");
|
||||
test(buffer);
|
||||
|
||||
memset((char*)buffer, 0, 32);
|
||||
strcpy((char*)buffer, "Hello World!\0");
|
||||
test(buffer);
|
||||
|
||||
memset((char*)buffer, 0, 32);
|
||||
strcpy((char*)buffer, "Hello Worlds\0");
|
||||
test(buffer);
|
||||
|
||||
memset((char*)buffer, 0, 32);
|
||||
strcpy((char*)buffer, "Testing\0");
|
||||
test(buffer);
|
||||
|
||||
free(buffer);
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "tinycrc.h"
|
||||
|
||||
/*
|
||||
CRC16
|
||||
CRC16 (from https://stackoverflow.com/questions/10564491/function-to-calculate-a-crc16-checksum)
|
||||
*/
|
||||
|
||||
uint16_t tinycrc_crc16(const uint8_t *data, uint16_t size)
|
||||
@ -19,4 +19,4 @@ uint16_t tinycrc_crc16(const uint8_t *data, uint16_t size)
|
||||
crc = (crc << 8) ^ ((unsigned short)(x << 12)) ^ ((unsigned short)(x <<5)) ^ ((unsigned short)x);
|
||||
}
|
||||
return crc & 0xFFFF;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user