diff --git a/Makefile b/Makefile index 114036f..0b91139 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,4 @@ - .PHONY: all all: tinycrc.a crctest diff --git a/README.md b/README.md index a4681d6..ae43b16 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ # TinyCRC -This is a library for calculating CRC32, CRC16 and CRC8. \ No newline at end of file +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. \ No newline at end of file diff --git a/crctest.cpp b/crctest.cpp index c29935e..1ad66b3 100644 --- a/crctest.cpp +++ b/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); - } diff --git a/src/crc16.cpp b/src/crc16.cpp index 42311d8..38ae8f0 100644 --- a/src/crc16.cpp +++ b/src/crc16.cpp @@ -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; -} \ No newline at end of file +}