以下是一个计算CRC_16值的示例代码:

#include <stdint.h>

uint16_t crc16(uint8_t *data, uint32_t len)
{
    uint16_t crc = 0xFFFF;

    for (uint32_t i = 0; i < len; i++)
    {
        crc ^= data[i];

        for (uint8_t j = 0; j < 8; j++)
        {
            if (crc & 0x0001)
            {
                crc >>= 1;
                crc ^= 0xA001;
            }
            else
            {
                crc >>= 1;
            }
        }
    }

    return crc;
}

该函数接受一个指向数据缓冲区和数据长度的指针,并返回计算出的CRC_16值。在计算过程中,函数采用了标准的CRC-16/CCITT算法,使用了多项式0x1021和初始值0xFFFF

QT 计算CRC_16的值

原文地址: https://www.cveoy.top/t/topic/hbZU 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录