I am trying to write binary literals in a cleaner format.
I understand that the following can be done for integer literals:
int x = 1234_5678_9999;
I assumed this would work for binary literals, so I tried:
uint32_t branch_bitmask = 0b0000_1111_0000_0000_0000_0000_0000_0000;
Which gives me an "invalid suffix" error for everything past the first underscore.
Is there an alternative to underscores that would allow me to write the binary literal in a cleaner way than just:
uint32_t branch_bitmask = 0b00001111000000000000000000000000;
If you always have the same number of bits (32 in your example) you could #define a macro a bit like this:
and then call it like this:
or you can go further and use
##in the macro to prepend the0b.But the simple answer for me has always been to use hexadecimal, as one hex digit is 4 bits.