I work with registers a bit, and data sheets that turn everything into bit indices. Luckily, I'm using GCC, which has the binary literal extension syntax so that i can do things like
register |= 0b01000010;
The other option is of course to just use hexadecimal format
register |= 0x42;
Despite having worked with hexadecimal numbers a bit over time, I still find binary format better for this kind of bit banging. I still decompose the 4 and 2 nibbles into their 0100 and 0010 patterns. So I think the binary format visualizes better. The problem with the binary format though, is that it's hard to find the boundaries. Using hexadecimal format, the nibbles separate nicely and so you can "index" bits safer sometimes. In other words, in the top I have to worry I didn't add or omit an extra 0 and end up with bit 7 on instead of 6.
Has a technique/trick been developed to have their cake and eat it too? When you have two string constants adjacent in C
"Hello " "World"
The compiler is smart enough to just mash them together into one literal. It would be nice if there was a way to do something similar with these binary numbers, e.g.,
0b0100 0010
I could do something weird with macros, perhaps
#define _(a, b) (((a) << 4) | (b))
and then be able to do
_(0b0100,0b0010)
but that's honestly worse, and limited to a pair of nibbles. Is there something clever and nice?