Cleanup example
This commit is contained in:
parent
4fd5bc05c9
commit
6703a07e0f
3
README.md
Normal file
3
README.md
Normal file
@ -0,0 +1,3 @@
|
||||
# TinyCRC
|
||||
|
||||
This is a library for calculating CRC32, CRC16 and CRC8.
|
44
crctest.cpp
44
crctest.cpp
@ -4,41 +4,33 @@
|
||||
#include <cstring>
|
||||
#include "src/tinycrc.h"
|
||||
|
||||
void test(const uint8_t* buffer)
|
||||
{
|
||||
uint32_t crc32 = tinycrc_crc32(buffer, strlen((char*)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);
|
||||
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
uint8_t* buffer = (uint8_t*)malloc(32);
|
||||
|
||||
sprintf((char*)buffer, "Hello %s!", "World");
|
||||
strcpy((char*)buffer, "Hello World\0");
|
||||
test(buffer);
|
||||
|
||||
uint32_t crc32 = tinycrc_crc32(buffer, 32);
|
||||
uint16_t crc16 = tinycrc_crc16(buffer, 32);
|
||||
uint8_t crc8 = tinycrc_crc8(buffer, 32);
|
||||
strcpy((char*)buffer, "Hello World!\0");
|
||||
test(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);
|
||||
strcpy((char*)buffer, "Hello Worlds\0");
|
||||
test(buffer);
|
||||
|
||||
sprintf((char*)buffer, "Hello %s!", "Worlds");
|
||||
|
||||
crc32 = tinycrc_crc32(buffer, 32);
|
||||
crc16 = tinycrc_crc16(buffer, 32);
|
||||
crc8 = tinycrc_crc8(buffer, 32);
|
||||
|
||||
printf("%-32s | crc32 | %08x\n", (char*)buffer, crc32);
|
||||
printf("%-32s | crc16 | %04x\n", (char*)buffer, crc16);
|
||||
printf("%-32s | crc8 | %02x\n", (char*)buffer, crc8);
|
||||
|
||||
sprintf((char*)buffer, "%s %d", "foobarxyzzy", 42);
|
||||
|
||||
crc32 = tinycrc_crc32(buffer, 32);
|
||||
crc16 = tinycrc_crc16(buffer, 32);
|
||||
crc8 = tinycrc_crc8(buffer, 32);
|
||||
|
||||
printf("%-32s | crc32 | %08x\n", (char*)buffer, crc32);
|
||||
printf("%-32s | crc16 | %04x\n", (char*)buffer, crc16);
|
||||
printf("%-32s | crc8 | %02x\n", (char*)buffer, crc8);
|
||||
strcpy((char*)buffer, "Testing\0");
|
||||
test(buffer);
|
||||
|
||||
free(buffer);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user