Created
February 22, 2021 14:18
-
-
Save sriramster/bdfb5cdf1f00727a9e643b623e63bc0b to your computer and use it in GitHub Desktop.
This file contains 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 <inttypes.h> | |
uint32_t rev(uint32_t x) | |
{ | |
x = (x & 0x55555555) << 1 | (x >> 1) & 0x55555555; | |
x = (x & 0x33333333) << 2 | (x >> 2) & 0x33333333; | |
x = (x & 0x0F0F0F0F) << 4 | (x >> 4) & 0x0F0F0F0F; | |
x = (x << 24) | ((x & 0xFF00) << 8) | | |
(x >> 8) & 0xFF00 | (x >> 24); | |
return x; | |
} | |
int main(int argc, char *argv[]) | |
{ | |
uint32_t i = atoi(argv[1]); | |
printf("%ld", rev(i)); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment