Created
February 2, 2025 10:28
-
-
Save aneury1/2da360d1a279a4b44fa48c30a6d7c0a0 to your computer and use it in GitHub Desktop.
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
// ReverseByte.cpp | |
uint8_t reverse_byte(uint8_t b){ | |
unsigned int v = b; | |
unsigned int r = v; | |
int s = sizeof(b) * CHAR_BIT - 1; | |
for(v>>=1;v;v>>=1){ | |
r <<= 1; | |
r |= v&1; | |
s--; | |
} | |
r <<= s; | |
return r; | |
} | |
int main(){ | |
auto ik = 0x0F; | |
auto ki = reverse_byte(ik); | |
std::cout << std::hex <<(int)ki <<"\n"; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment