Created
November 11, 2019 08:08
-
-
Save rosek86/ffa33a476aa49f5f31708ead52aecf23 to your computer and use it in GitHub Desktop.
uint32_t bits revelsal in c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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