SBAA106A June   2020  – August 2021

2. 1Introduction
3. 2Simple Checksum
4. 3CRC
1. 3.1 CRC Generic Computations
1. 3.1.1 Using XOR Bitwise Computation
2. 3.1.2 Using Lookup Tables
5. 4Hamming Code
1. 4.1 Hamming Code Computation
1. 4.1.1 Hamming Code Computation Example
2. 4.1.2 Validation of Transmitted Data
6. 5Summary
7. 6References
8. 7Revision History
4.1.1.1.1 Example of Counting Set Bits in the Data

One method of computing the number of bits set in the data is to evaluate each bit one at a time. The following method requires 32 passes through the data to evaluate each of the 32 bits.

/**
* Computation of the number of set bits in a 32-bit value.
*
* \details Counting of the number of bits set in a value using a loop and
* evaluating each least significant bit and then right shifting the remaining value by 1.
*
* \param    uint32_t in of the value to be computed.
*
* \returns  uint32_t numBits of the computation.
*/
uint32_t countBits (uint32_t in)
{
uint32_t numBits = 0;
while (in != 0)
{
if (in & 0x01) numBits++;
in >>= 1;
}
return numBits;
}