Nick Hounsome said:
Not as much as you would think.
Maybe not in your work. I use bitwise operators all the time.
The usually quoted use is for interfaceing to hardware but bitfields not
portable between different compilers because the standard doesn't mandate
how they are laid out or accessed (or it didn't - please feel free to
correct me on this) Consequently it is probably safer to stick to masks and
bit operators &,|,^
The only good use is if you really have to use the absolute minimum space
but even then it may not sit as well with class abstraction as bit masks -
consider standard i/o - iostate and fmtflags both use masks because they
have to for the interface and once they are defined for the interface it
would be foolish to use bitfields in the implementation
Nick
Nick,
Where did "bitfields" come into this conversation? He asked about
"bitwise operators", which, to me, means the operators like & and |.
Nothing to do with bitfields.
To the original poster:
the reason bitwise operators are used for hardware is because hardware
is connected to the computer/processor via sets of wires, usually through
some kind of I/O port device. The hardware being addressed gets its control
informaton by which bits in that connecton are on (1) or off (0). And, the
easiest way to turn a bit on is to OR (|) it with a binary value which has
only that bit set. Likewise, to set a bit to zero, you would AND (&) it
with a binary value which has all bits *except* that one set.
It's also an easy (and compact) way to pass a set of booleans between
software objects. Instead of sending eight boolean values, you set the bits
of one unsigned char (for example), and send that in one shot.
-Howard