39. Bitwise Rotation and Counting-II

Question.2

A developer reverses the bits of an 8-bit value for SPI LSB-first transmission:

uint8_t reverse(uint8_t val) {
   uint8_t result = 0;
   for (int i = 0; i < 8; i++) {
       result <<= 1;
       result |= (val & 1);
       val >>= 1;
   }
   return result;
}

He calls reverse(0x1A). Will the result be 0x58 (01011000)?

Need Help? Refer to the Quick Guide below

Select Answer