Last active
October 9, 2017 15:10
-
-
Save xymopen/4ceeb2cbd9a159179c4bd01b01497882 to your computer and use it in GitHub Desktop.
Code snippet to reverse a byte from StackOverflow
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
// https://stackoverflow.com/questions/2602823/in-c-c-whats-the-simplest-way-to-reverse-the-order-of-bits-in-a-byte | |
unsigned char rvs_byte( unsigned char b ) { | |
b = ( b & 0b11110000 ) >> 4 | ( b & 0b00001111 ) << 4; | |
b = ( b & 0b11001100 ) >> 2 | ( b & 0b00110011 ) << 2; | |
b = ( b & 0b10101010 ) >> 1 | ( b & 0b01010101 ) << 1; | |
return b; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment