Bitwise is a level of operations that involves working with individual bits, which are the smallest units of data in a computer. Each bit has a single binary value: 0 or 1. Although computers are capable of manipulating bits, they usually store data and execute instructions in bit multiples called bytes. Most programming languages manipulate groups of 8, 16 or 32 bits.
Bitwise operators are characters that represent actions to be performed on single bits. A bitwise operation operates on two-bit patterns of equal lengths by positionally matching their individual bits:
A logical AND (&) of each bit pair results in a 1 if the first bit is 1 AND the second bit is 1. Otherwise the result is zero. Among other uses, AND (represented as &) can be used to test individual bits in a bit string to see if they are 0 or 1.
Here’s an example in C/C++:
IsOdd = (ValueToTest & 1) != 0;
A logical OR (|) of each bit pair results in a 1 if the first bit is 1 OR the second bit is 1. Otherwise, the result is zero. A logical XOR (~) of each bit pair results in a 1 if the two bits are different, and 0 if they are the same.
Logical NOT is represented as ^. Left shift (<<), right shift (>>) and zero fill right shift (>>>>) are sometimes referred to as bitwise operators and sometimes called bit shift operators.