Binary literals

Introduced by: C++14

Until C++14, standard C++ allowed to define numbers in:

  • decimal notation:
    int number = 7;
  • hexadecimal notation:
    int number = 0x7;
  • octal notation:
    int number = 07;

Anyhow, without special compiler extensions it was not allowed to define numbers in binary format. It changes from C++14. The core language supports binary literals. It’s possible to define integer with 0b or 0B prefix to represent binary number.

int number = 0b0111;

It’s worth noticing that the GCC compiler has offered the possibility to define binary numbers since GCC 4.3.

It may be not the most crucial feature of C++ standard, but I believe there are cases when use of binary representation will improve readability of the code.

Advertisements

2 thoughts on “Binary literals

  1. lududkiller says:

    oh didn’t knew about that one, I am thinking of starting with C++ once again, I gave up earlier because version changes incorporated so much changes :/
    It will still be a steep learning curve and even steeper mastering curve :(

    Like

    • katecpp says:

      Of course I recommend you to start again :). However, not everybody has to like and master C++. If you don’t enjoy it, don’t force yourself and master another language which is more pleasant for you. Still I have my fingers crossed for your learning!

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s