Created
December 28, 2015 21:58
-
-
Save knielsen/a91305a83517d48cdc67 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
uint8_t swap_bits(uint8_t value, uint8_t bit1, uint8_t bit2) | |
{ | |
uint8_t mask1 = 1 << bit1; | |
uint8_t mask2 = 1 << bit2; | |
uint8_t result = value & ~(mask1 | mask2); | |
result |= ((value & mask1) >> bit1) << bit2; | |
result |= ((value & mask2) >> bit2) << bit1; | |
return result; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment