Created
March 26, 2012 03:24
-
-
Save cammckinnon/2202649 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
/* borrowed partially from: http://stackoverflow.com/a/7577517/277800 */ | |
#define B_0000 0 | |
#define B_0001 1 | |
#define B_0010 2 | |
#define B_0011 3 | |
#define B_0100 4 | |
#define B_0101 5 | |
#define B_0110 6 | |
#define B_0111 7 | |
#define B_1000 8 | |
#define B_1001 9 | |
#define B_1010 a | |
#define B_1011 b | |
#define B_1100 c | |
#define B_1101 d | |
#define B_1110 e | |
#define B_1111 f | |
// add a level of indirection to a preprocessor token | |
#define INDIRECT(a) a | |
// convert 4 bits to a hex character | |
#define B2H(b) B_##b | |
// bits -> hex | |
#define NIB(b1) INDIRECT(0x)##B2H(b1) | |
#define BYT(b1, b2) INDIRECT(0x)##B2H(b1)##B2H(b2) | |
#define WRD(b1, b2, b3, b4, b5, b6, b7, b8) INDIRECT(0x)##B2H(b1)##B2H(b2)##B2H(b3)##B2H(b4)##B2H(b5)##B2H(b6)##B2H(b7)##B2H(b8) | |
#define DWR(b1, b2, b3, b4, b5, b6, b7, b8, b11, b22, b33, b44, b55, b66, b77, b88) INDIRECT(0x)##B2H(b1)##B2H(b2)##B2H(b3)##B2H(b4)##B2H(b5)##B2H(b6)##B2H(b7)##B2H(b8)##B2H(b11)##B2H(b22)##B2H(b33)##B2H(b44)##B2H(b55)##B2H(b66)##B2H(b77)##B2H(b88) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment