Mike Hodkin wrote:
As a beginning student of C++, books reference "bitwise operators" and give
brief examples, but I have not read a good explanation of what they are used
for. One reference mentioned that they are used in hardware programming.
Are they used very often in routine C/C++ programming, and what for?
Yes, they are "often" used.
Although there are alternatives (bit fields), some code uses bitwise
operators to manage "flags".
For example in the Posix open() call where you can set alternative modes
for openning a file. The "select" system call also uses a "bitmask" to
select which fd's are interesting.
They are also used when manipulating data, for example when you want to
convert from big endian to little endian.
Certain arithmentic operations are also much less expensive as bit
operations. For example, if you want a number that is the next largest
multiple of a power of 2 - ( 1 + ( ( N - 1 ) | ( ( 1 << P ) - 1 ) ).
It's also used in cryptography, the xor "^" operator is a very useful
transform since ( ( A^B ) ^B ) == A . This is also used in computation
of RAID checksums. If you look up "raidzz" it's somthing I wrote a few
years ago that makes used of bitwise functionality.
There are plenty more.