Already a member? Log in
Please enter your username below and press the send button.A password reset link will be sent to you.
If you are unable to access the email address originally associated with your Delicious account, we recommend creating a new account.
http://bytes.com/topic/c/answers/216333-binary-constant-macros
Recently Saved by vtpg on December 13, 2011
First saved by rentzsch on December 12, 2011
Binary constant macros. C / C++ Forums on Bytes.
Comments
ddribin
Neat hack to get compile-time binary constants in C using the preprocessor.
vtpg
B8(10101010). Works by stringifying to hex, then masking & adding. B32, etc work by using B8 and shifting.
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;
(compile-time constant)"
epicycle