Are the bitwise operators very useful or is just there if anyone prefers it, cause I cant really visualize there effects so its hard for me to figure out whats going on. |
The most common use for bitmasks and bitwise operators that I've seen (*) is as an easy way to pack several boolean flags into one variable.
Consider a char. Typically, a char will have 8 bits. If set to 0 (or '\0' if you prefer), then the bits are:
00000000
If set to 2, then:
00000010
If set to 7:
00000111
etc.
If, for some reason, you needed to use up to 8 boolean flags for something, then you can use each of those bits to store a single flag, so that you can use a single char to store those 8 flags. You can then use bitmasks and bitwise operators to set and read the values of each flag independently.
This is known as using "bit flags", and I imagine a Google search for "C++ bit flags" will get you more information on how to use them. Often, you'll find that third-party software uses them in their interface.
Edit: Other than that, you find them used in things like interfaces to hardware, communication protocols, and other low-level areas where it's helpful to pack as much data into the smallest amount of memory as possible.
(*) Other peoples' experiences may differ from mine, of course.