Last active
April 19, 2018 07:15
-
-
Save Marzogh/ef612d368718dc3941c8ec2b0d698e18 to your computer and use it in GitHub Desktop.
A list of macros that can be used to carry out bit manipulation
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
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// | |
// Bit manipulation macros // | |
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// | |
//Extract bytes from integers, floats & doubles | |
#define Lo(param) ((char *)¶m)[0] //0x000y | |
#define Hi(param) ((char *)¶m)[1] //0x00y0 | |
#define Higher(param) ((char *)¶m)[2] //0x0y00 | |
#define Highest(param) ((char *)¶m)[3] //0xy000 | |
//Extract nibbles from integers, floats & doubles | |
#define Low(param) ((int *)¶m)[0] //0x00yy | |
#define Top(param) ((int *)¶m)[1] //0xyy00 | |
// Set bit and clear bit | |
// x -> byte, y -> bit | |
#define setBit(x, y) x |= (1 << y) | |
#define clearBit(x, y) x &= ~(1 << y) | |
#define toggleBit(x, y) x ^= (1 << y) | |
// Query to see if bit is set or cleared. | |
// x -> byte, y -> bit | |
#define bitIsSet(x, y) x & (1 << y) | |
#define bitIsClear(x, y) !(x & (1 << y)) | |
//Set nibbles | |
// x -> byte, y -> value to set | |
#define setLowerNibble(x, y) x &= 0xF0; x |= (y & 0x0F) // Clear out the lower nibble // OR in the desired mask | |
#define setUpperNibble(x, y) x &= 0x0F; x |= (y & 0xF0) // Clear out the lower nibble // OR in the desired mask |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment