you can't write binary numbers in C++. Fortunately hexadecimal is used for this very reason!
A 32 bit number in binary can be very hard to read: 00111101101111001010000111101001
If you want to know what bit 25 is, you really have to put a pencil on the screen and count each digit. A hexadecimal digit represents a set of 4 binary numbers. IN this case, the number above looks like this: 0x3dbca1e9
It's still looks a little garbled, but with some practice you can get to understand it better. In this case, if I want to know what bit 25 is, I think that is the first bit in the 7th letter. Why? Because 4bits per letter * 6 letters =24 bits. Then one more bit into the 7th letter is our bit. The 7th letter is D, which is 1101, therfore the 25th bit is 1.
Get to know your hex<-->bin conversions (there are only 16) and you'll never want to look at binary again. It's awful!
For your case you have 0x64, 6 is 0110 and 4 is 0100. So 0x64 is 01100100
It feels like just yesterday C++0x wasn't assigned a year. We have C++14 already? But compilers are just starting to get up-to-date with C++11!
I think adding binary literals will make things easier for beginners, but then also just promote bad practices. In what world would you ever want to read binary over hex? Allowing people to code in binary will just make life harder for those of us who use hex when we review those people's code.
> In what world would you ever want to read binary over hex?
In this world, when I want to deal with bits in groups that are not a multiple of four. For instance, to test a std::bitset<5> for a specific combination of bits.
Thank you for your answer.
JLBorges, I am working on a code for writing PBM image files in binary mode. In those files, 1 means black and 0 means white, so, to write for instance a line of three colors 101, you need to write the binary value of 10100000 which is the character 0xA0. For a line of 01000000, you will write the character 0x64.
If I already know the binary scheme of a character, I would like to use it directly instead of looking for the hex value.