Binary Integer Literals In C++ 14

With C++  close relationship  with the hardware.  I was always mystified by the lack of  support for base 2  literals.   It’s  common to see header files such as :


const unsigned int can_read_files   = 1; // 00000001
const unsigned int can_write_files  = 2; // 00000010
.
const unsigned int can_delete_files = 32; //00100000

It works but I find this  less readable than it could be.  a typo is no readily obvious and can trigger strange behavior .

That is way I was pleased to find out that with C++ 14  you can now enter binary literal directly by  prefixing it with either 0b  or 0B :

const unsigned int  can_delete_files = 0b00000001;
const unsigned int  can_write_files  = 0b00000010;
const unsigned int  can_move_files   = 0b00000100;

Which  I find more to the point.

Conclusion

Whenever possible it’s  better to leave the boring repetitive  computation stuff  to the compiler it’s much better at this than us.