# CRC8, XOR, LRC

This value is often used in checksum calculations.

```cpp
uint8_t CRC8_u8Calc(uint8_t *pu8Data, uint8_t size, uint8_t init=0)
uint8_t CRC8_u8CalcU32(uint32_t u32c, uint8_t init=0)
uint8_t CRC8_u8CalcU16(uint16_t u16c, uint8_t init=0)
uint8_t XOR_u8Calc(uint8_t *pu8Data, uint8_t size)
uint8_t LRC_u8Calc(uint8_t* pu8Data, uint8_t size)
```

CRC8, XOR, LRC([ASCII format](/latest_en/api-reference/classes/ser_parser.md#asuk)) calculations.

`CRC8_u8CalcU16(), CRC8_u8CalcU32()` computes CRC8 using `u16c, u32c` as big-endian sequence.

{% hint style="info" %}
There are different types of CRC8 depending on the calculation formula, initial value, etc. This library uses a polynomial formula of `X^8+X^5+X^4+1` (Polynomial Value is 0x31). This is sometimes called CRC8-CCITT or CRC8-Maxim.
{% endhint %}

{% hint style="info" %}
XOR is the exclusive OR XOR of each element.
{% endhint %}

{% hint style="info" %}
LRC calculates the sum of the values of each element and takes the two's complement of the lower 8 bits. The result is zero when all elements, including the checksum, are added together.
{% endhint %}

## Background

Added as a library procedure because it is used to check data strings in wireless packets, checksums (LRC) in ASCII format, and various sensors.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mwx.twelite.info/latest_en/api-reference/funcs/utility/checksum.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
