The Bitwise Operator

By ruzaib khan

What is a bitwise operator?

The Bitwise NOT

Also called the bitwise complement, the unary NOT operator, ~, inverts all of the bits of its operand. For example, the number 42, which has the following bit pattern:

00101010 becomes 11010101 after the NOT operator is applied.

The Bitwise AND

The AND operator, &, produces a 1 bit if both operands are also 1. A zero is produced in all other cases. Here is an example:

00101010 42
&00001111 15
--------------
00001010 10

The Bitwise OR

The OR operator, |, combines bits such that if either of the bits in the operands is a 1, then the resultant bit is a 1, as shown here:

00101010 42
| 00001111 15
--------------
00101111 47

The Bitwise Operator  (2098 Views)