23 lines
447 B
C
23 lines
447 B
C
#include "user_lib.h"
|
|
|
|
/**
|
|
* 计算并返回指定数据区域异或的值
|
|
*
|
|
* @param data: 待计算的数据区首地址
|
|
* @param length: 待计算的数据区长度
|
|
*
|
|
* @return 异或计算的结果
|
|
*/
|
|
uint8_t xor_compute(const uint8_t *const data, uint16_t length)
|
|
{
|
|
uint16_t i;
|
|
const uint8_t *ptr = data;
|
|
uint8_t xor = 0;
|
|
for (i = 0; i < length; i++)
|
|
{
|
|
xor ^= *ptr;
|
|
ptr++;
|
|
}
|
|
return xor;
|
|
}
|