Skip to content

Instantly share code, notes, and snippets.

@rosek86
Created November 11, 2019 08:08
Show Gist options
  • Select an option

  • Save rosek86/ffa33a476aa49f5f31708ead52aecf23 to your computer and use it in GitHub Desktop.

Select an option

Save rosek86/ffa33a476aa49f5f31708ead52aecf23 to your computer and use it in GitHub Desktop.
uint32_t bits revelsal in c
#include <stdio.h>
#include <stdint.h>
uint32_t bits_reverse_u32(uint32_t val) {
uint32_t out = 0;
for (int i = 0; i < 16; i++) {
out |= ((val & (1 << ( i))) << (31 - (i << 1)));
out |= ((val & (1 << (31 - i))) >> (31 - (i << 1)));
}
return out;
}
int main(void) {
uint32_t val = 0x3576CB1A;
uint32_t out = bits_reverse_u32(val);
printf("0x%08x\n", out);
if (out == 0x58d36eac) {
printf("OK\n");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment