Bitwise Operator in C
Bitwise Operator in C
Bitwise Operator:
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 computations to make the calculations faster.
We have different types of bitwise operators in the C programming language. The
following is the list of the bitwise operators:
0 0 0 0 0
0 1 0 1 1
1 0 0 1 1
1 1 1 1 0
Bitwise AND operator
Bitwise AND operator is denoted by the single ampersand sign (&). Two integer operands
are written on both sides of the (&) operator. If the corresponding bits of both the operands
are 1, then the output of the bitwise AND operation is 1; otherwise, the output would be 0.
For example:
We have two variables a and b.
a =6;
b=4;
The binary representation of the above two variables are given below:
a = 0110
b = 0100
When we apply the bitwise AND operation in the above two variables, i.e., a&b, the output would be:
Result = 0100
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 of the operand is 1, then
the output would be 1, otherwise 0.
For example,
Two types of bitwise shift operators exist in C programming. The bitwise shift
operators will shift the bits either on the left-side or right-side. Therefore, we can
say that the bitwise shift operator is divided into two categories:
Left-shift operator
Right-shift operator
Left-shift operator