All submissions

Bit Reversal in an 8-bit Value

Code

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

uint8_t reverse_bits(uint8_t val) {

  uint8_t out = 0;

  for (int i = 0; i < 8; i++) {
    out <<= 1;
    out |= val & 1;
    val >>= 1;
  }

  return out;
}

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