Binary Literals & Digit Separators (C++14)

More readable numeric literals

Binary Literals

C++14 allows binary literals using the 0b or 0B prefix, making bit manipulation clearer.

// Binary literals with 0b prefix
int flags = 0b10110100;    // Binary: 180 in decimal
int mask = 0b11110000;     // Binary: 240 in decimal

// Combining flags
int combined = 0b1010 | 0b0100;  // Result: 0b1110

// Bit manipulation becomes readable
if (value & 0b1000) {  // Check if 4th bit is set
    // Do something
}

Digit Separators

Use single quotes to separate digits for better readability.

// Decimal with separators
int million = 1'000'000;
int billion = 1'000'000'000;

// Binary with separators
int binary = 0b1010'1100'0011'0000;

// Hex with separators
int hex = 0xDEAD'BEEF;

// Float with separators
double pi = 3.141'592'653'589;

// Makes large numbers readable
long long credit_card = 4532'1234'5678'9012;