So, the CRC can be written as CRC = data % 2 polynomial Mathematically spoken, a CRC is the remainder of a modulo-2 polynomial division of the data. For the remainder of this article, we’ll stick with the big-endian format and provide some hints along the way on how a little-endian implementation would differ. It’s usually required by the hardware to use a particular byte order. So the question arises which endianness to use for CRC?įrom an app developer’s perspective, the answer is quite simple: We use the same endianness as the system we want to communicate with. However, in many cases, we use CRCs that consist of mulitple bytes. In the introductory example (with the letter z), we only used a CRC with a size of 1 byte, so the endianness doesn’t matter in this case. In terms of data transmission, the most significant byte is transmitted first.
Big-endian: The most significant byte is stored at the smallest memory address.
In terms of data transmission, the least significant byte is transmitted first.
The BasicsĬRC is an error detection code used for verifying the integrity of data. However, after reading this article you should have a good understanding of what a CRC is and how it works. The name sounds rather complex and intimidating. It is also used to check the integrity of different types of files such as Gzip, Bzip2, PNG etc.
It is often used in Bluetooth and other wireless communication protocols. The most common one is called Cyclic Redundancy Check (CRC). There are a number of mechanisms used for data error detection. So whenever you exchange data with other systems, how do you make sure that the data you receive is exactly the same as the data that was sent to you? How do you detect accidental changes in your data stream? Or in other words, how do you check the integrity of your data against unintended changes and losses? Simply accessing a flash memory might also result in bit flips. Surrounding electromagnetic radiation can interfere with your Bluetooth or wi-fi signals and cause unintended changes in your data stream. Individual bits can get flipped or even bursts of multiple bits, changing the value and the meaning of your data inadvertently. But whenever you transmit data or store it somewhere on a physical drive, it can get corrupted. The cool thing about programming is that there is an absolute truth in every Bit: It’s either black or white, 1 or 0, true or false.