SBAA106A June 2020 – August 2021 ADS112C04 , ADS112U04 , ADS114S06 , ADS114S08 , ADS122C04 , ADS122U04 , ADS1235 , ADS1235-Q1 , ADS124S06 , ADS124S08 , ADS1259 , ADS1259-Q1 , ADS125H01 , ADS125H02 , ADS1260 , ADS1260-Q1 , ADS1261 , ADS1262 , ADS1263 , ADS127L01 , ADS131A02 , ADS131A04 , ADS131M04 , ADS131M06 , ADS131M08
The following code example is a method to reverse, or reflect, the order of bits within a byte. The order of b7, b6, b5, b4, b3, b2, b1, b0 is reflected to the returned bit order of b0, b1, b2, b3, b4, b5, b6, b7.
/**
* Reverses the bit order of a byte.
*
* \details Reorders the bits in reverse order of byte submitted
* and returns byte as unsigned byte. This is required as the data is always
* transmitted out the UART lsb first when comparing TX and RX data.
*
* \param uint8_t u8Byte data byte to be reversed.
*
* \returns uint8_t u8RevByte.
*/
uint8_t revByte(uint8_t u8Byte)
{
uint8_t u8i, u8RevByte = 0; // For each bit in the byte, starting with bit 0
for (u8i = 0; u8i < 8; u8i++)
{
u8RevByte |= (u8Byte & 0x01); // Take one bit of the input byte and store it
// in the new byte
u8Byte >>= 1; // Get the next bit
if (u8i < 7) u8RevByte <<= 1; // Do not shift the last bit of the new byte
}
return u8RevByte;
}