2014-11-17 CPlusPlus11

Binary Literals

One tiny(!?) extension that comes with C++14 is binary literals. You can now write them by prefixing the binary number with 0b. This is a well known syntax from other languages and in fact has been around a while even as a gcc extension. So you might not even recognize this as new feature.

Anyway, it looks like this:

   int b1 = 0b10;
   int b2 = 0B1010;     // Capital B is OK too!

It goes well with digit separators too. You can write:

   int b3 = 0b1010'1010;
   int b4 = 0B010'101'010;