In the process of data transmission through the network and serial port, there may be data errors. In order to ensure the integrity and correctness of data transmission, it is necessary to adopt some methods to determine whether the data is correct and complete, or to perform immediate correction when the data is incorrect. Commonly used data checking methods include parity check, CRC check, LRC check, Gray code check, sum check, exclusive OR check and so on.
XOR (BCC) check: In fact, it is a parity check, and it is also the most commonly used and most efficient check method. The so-called BCC verification method is to perform bitwise exclusive OR of all characters of the character before and after sending, and compare the characters obtained after conversion as required. If they are equal, the communication is considered as error-free, and if they are not equal, the communication is considered as communication. Something went wrong.
The specific algorithm of BCC is: After each byte of data is XORed sequentially, the check code is finally obtained.
For example: BCCXOR
Hexadecimal: 42 43 43 58 4F 52
XOR calculation: 42 xor 43 xor 43 xor 58 xor 4F xor 52 = 07
BCC check code: 07