The bitwise operators are the operators used to perform the operations on the data at the bit-level. When we perform the bitwise operations, then it is also known as bit-level programming. It consists of two digits, either 0 or 1. It is mainly used in numerical calculations to speed up calculations.
What are Bitwise Operators?
Bitwise operators are used to handle data at the bit level, also known as bit level programming. Bitwise works on one or more bit patterns or binary digits at the level of their individual bits. They are used in numerical calculations to speed up the calculation process.
Bitwise logical operators work on the smallest bit of data, starting with the least important bit.
One thing to always keep in mind is that Bitwise operators are mostly used with integer data types because of its compatibility.
Following is the list of bitwise operators provided by ‘C’ programming language:
Operator |
Meaning of operator |
& |
Bitwise AND operator |
| |
Bitwise OR operator |
^ |
Bitwise
exclusive OR operator |
~ |
One's
complement operator (unary operator) |
<< |
Left
shift operator |
>> |
Right
shift operator |
Bitwise operators cannot be directly applied to primitive data types such as float, double, etc.
X |
Y |
X&Y |
X|Y |
0 |
0 |
0 |
0 |
0 |
1 |
0 |
1 |
1 |
0 |
0 |
1 |
1 |
1 |
1 |
1 |
Bitwise AND
It is one of the most commonly used logical bitwise operators. It is represented by a single ampersand sign (&). Two integer expressions are written on each side of the (&) operator.
If both bits have a value of 1 then the result of bitwise AND operation is 1; Otherwise, the result is always 0.
Bitwise OR operator
The bitwise OR operator is represented by a single vertical sign (|). Two integer operands are written on both sides of the (|) symbol. If the bit value of any operand is 1, the output will be 1, otherwise 0.
Bitwise XOR (exclusive OR) operator
If the corresponding bits of the two operands are opposite, then the result of the bitwise XOR operator is 1. It is denoted by ^.