Skip to content

Modern C++ • Binary literals & Digit separators

Yet another small useful feature that’s already available in many other languages as a core syntax construct has been brought into C++. Probably you have been wondering why it is possible to write numeric literals in decimal and hexadecimal form but not in the native language of computers, that is in binary notation. Well, it is now possible using Binary Literals with the 0b or 0B prefixes, like so

auto a = 0b10011110;   // 158
auto b = 0B11111111;   // 255

In addition, the single quote character ' can be used as digit separator, like so

auto value = 0b1001'1110;
auto balance = 15'085'970;
auto color = 0xAA'D7'9C;


Published inModern C++