Pseudocode
International standard ISO 1155 states that a longitudinal redundancy check for a sequence of bytes may be computed in software by the following algorithm:
Set LRC = 0 For each byte b in the buffer do Set LRC = (LRC + b) AND 0xFF end do Set LRC = (((LRC XOR 0xFF) + 1) AND 0xFF)which can be expressed as "the 8-bit two's-complement value of the sum of all bytes modulo 28."
An 8-bit LRC such as this is equivalent to a cyclic redundancy check using the polynomial x8+1, but the independence of the bit streams is less clear when looked at that way.
Many protocols use such an XOR-based longitudinal redundancy check byte, (often called block check character or BCC), including the IEC 62056-21 standard for electrical meter reading, smart cards as defined in ISO/IEC 7816, and the ACCESS.bus protocol.
Read more about this topic: Longitudinal Redundancy Check