All submissions

Bit Reversal in an 8-bit Value

Extract lsb and then or with lsb of res then shift

#include <stdio.h>
#include <stdint.h>

uint8_t reverse_bits(uint8_t val) {
    // Your logic here
    uint8_t res = 0, i;
    for(i = 0; i<8 ; i++){
        res <<= 1;
        res |= val & 1U;
        val >>= 1;
    }   
    return res;
}

int main() {
    uint8_t val;
    scanf("%hhu", &val);

    uint8_t result = reverse_bits(val);
    printf("%u", result);
    return 0;
}

Solving Approach

 

 

 

Loading...

Input

26

Expected Output

88