When writing binary constants, it's tempting to write preceding zeros at the beginning of the number to pad it to a fixed number of bits. However, doing this here (eg. BIN(01001011)) would turn the decimal literal into an octal literal, giving entirely the wrong value.
The octal literals, far from being a problem, could be used just the same:
#define BIN_BITO(value, shift, mask) (((unsigned)value&mask)>>shift)
/* Put 10 bits together to form a 10 bit constant. */
#define BINO(value) \
( BIN_BITO(0##value, 0, 01) | \
BIN_BITO(0##value, 2, 010) | \
BIN_BITO(0##value, 4, 0100) | \
BIN_BITO(0##value, 6, 01000) | \
BIN_BITO(0##value, 8, 010000) | \
BIN_BITO(0##value, 10, 0100000) | \
BIN_BITO(0##value, 12, 01000000) | \
BIN_BITO(0##value, 14, 010000000) | \
BIN_BITO(0##value, 16, 0100000000) | \
BIN_BITO(0##value, 18, 01000000000) )
If you need bigger bit constants, this simple macro will do:
#define BIN32(b24,b16,b8,b0) \
((BINO(b24)&0xff<<24)| \
(BINO(b16)&0xff<<16)| \
(BINO(b8)&0xff<<8) | \
(BINO(b0)&0xff) )