blargg.h4g
11/28/2008 3:47:00 PM
Tarmo Kuuse wrote:
> Bill wrote:
> > Why would you prefer to write down strings of 0s and 1s anyway? Seems like
> > it would increase your chance of error. If you really wanted to, you
could
> > write your own function which translates binary character strings to an
> > integral data type. For instance, int binary2Int(const char *).
>
> When working at low level (embedded, device drivers, ...), bit fields
> are scattered throughout code. It is quite annoying to convert binary to
> hexadecimal and vice versa for 32-bit values.
>
> Let's see now, is bit 22 set in mask 0x03C00000? OK, give me a minute...
Is bit 22 set in this mask? OK, give me a minute...
00000011110000000000000000000000
How about this one? Simple, yes.
(1L << 25) | (1L << 24) | (1L << 23) | (1L << 22)
If you really want binary, you can write a macro (or template) that
accepts four 8-bit chunks, something like
BIN(00000011,11000000,00000000,00000000).