Possible Duplicate:
Can I use a binary literal in C or C++?
I am learning C and i recently found out that we can represent integers in different ways, like that:
(Assuming i
has "human-readable" value of 512.) Here are the representations:
int i = 512;
int i = 01000;
int i = 0x200;
Something like int i = 1000000000b
? This is funny but unfortunately no C compiler accepts that value.
The standard describes no way to create "binary literals". However, the latest versions of GCC and Clang support this feature using a syntax similar to the hex syntax, except it's b
instead of x
:
int foo = 0b00100101;
As stated, using such binary literals locks you out of Visual Studio's C and C++ compilers, so you may want to take care where and how you use them.
C++14 (I know, I know, this isn't C) standardizes support for binary literals.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With