Binary Constant Macros in C
Tom Torfs (via Jonathan Rentzsch):
I’ve been missing the lack of support for binary numeric literals in C. To get around it I wrote the following handy macros, which allows you to simply write something like:
whatever = B8(10101010);and will translate as:
whatever = 85;
3 Comments RSS · Twitter
Is it a convention among the members of a hidden sect that 10101010 is 85?
For me, 01010101 is 85.
@bob Yes, the quoted example is wrong. B8(10101010) = 170 and B8(01010101) = 85.
I believe that both gcc and clang support '0b' as a prefix for binary constants.
whatever = 0b10101010;
It's not standard C (or C++), though.