![](/media/cache/group/mbed-logo-square-512_3.png.50x50_q85.png)
CRC example to compute 32-bit CRC .
Diff: main.cpp
- Revision:
- 0:4ea3a9a52bb6
- Child:
- 1:6f792125397a
diff -r 000000000000 -r 4ea3a9a52bb6 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Dec 18 22:53:07 2017 +0000 @@ -0,0 +1,58 @@ +#include "mbed.h" +#include "mbed_crc.h" +#include "SlowCRC.h" +#include "FastCRC.h" + +#define FAST_COMPUTE 1 + +#if defined(FAST_COMPUTE) +#define CRC_TYPE FastCRC +#else +#define CRC_TYPE SlowCRC +#endif + +char test[] = "123456789"; +uint32_t crc; + +int crc_ibm_16bit() { + CRC_TYPE<uint16_t> ct(CRC_16BIT_IBM); + + ct.init(); + ct.compute((void *)test, strlen((const char*)test), &crc); + + printf("The CRC of 0x%x \"123456789\" is \"0xBB3D\" Result: 0x%x\n", + ct.get_polynomial(), crc); + ct.deinit(); + return 0; +} + +int crc_ccitt_16bit() { + CRC_TYPE<uint16_t> ct(CRC_16BIT_CCITT); + + ct.init(); + ct.compute((void *)test, strlen((const char*)test), &crc); + + printf("The CRC of 0x%x \"123456789\" is \"0x29B1\" Result: 0x%x\n", + ct.get_polynomial(), crc); + ct.deinit(); + return 0; +} + +int crc_32_bit() { + CRC_TYPE<uint32_t> ct(CRC_32BIT); + + ct.init(); + ct.compute((void *)test, strlen((const char*)test), &crc); + + printf("The CRC of 0x%x \"123456789\" is \"0xCBF43926\" Result: 0x%x\n", + ct.get_polynomial(), crc); + ct.deinit(); + return 0; +} + +int main() { + crc_ibm_16bit(); + crc_ccitt_16bit(); + crc_32_bit(); + return 0; +}