Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results

Binary Literals in VS2015 — I Can’t Wait!

Binary Literals in VS2015 — I Can’t Wait!

There are a couple of features of C/C++ in Visual Studio 2015 that are easy to overlook, but that I’m really looking forward to using. Two of those features that I’m most eagerly anticipating are support for binary literals and digit separators.

Kinda boring, you say?  Hardly!

If you work with hardware, you are certainly familiar with having to create definitions of register fields for your driver header files based on the definitions in the chipset data book.  The definitions are always of the form:

FRED Register (offset 0x40):


and the like.  This process always makes me nuts.  It forces me to sit down, write the bits in binary, and convert them to hex, so they eventually look like in the following:

The problem with this is (a) it’s an annoying process, and (b) the result is pretty much entirely opaque.  Once I’ve converted the definitions to hex, unless they’re very simple like the ones for FRED_INT_ENABLE and FRED_INT_PENDING in the above example, the definitions lose all intuitive meaning.  I can’t get a picture in my mind as to what these register bits look like.  Heck, I can barely tell at a glance if any of the fields I’ve defined overlap!

This is where binary literals and digit separators enter the picture.  Instead of the above hex nonsense, starting with VS 2015 you can quickly cook-up definitions like these:

Ah! I don’t know about you, but to me that looks one heck of a lot more clear.  I now can see which bits are contiguous, which are adjacent, and I get a nice picture of the register’s layout.

OK, so maybe it’s a small thing.  But it’s the kind of thing that I know will make my dealings with hardware easier.