## Bitwise operators

#### Q) Explain bitwise operators in C.

• C has the distinction of supporting special operators known as bitwise operators for the manipulation of data at the bit level. These operators are used for testing the bits or shifting them right or left. Bitwise operators may not be applied to float either double.
Operator Meaning
& Bitwise AND
| Bitwise OR
^ Bitwise exclusive OR
<< Left shift
>> Right shift

#### & (Bitwise AND):

• & is known as the bitwise AND. This operator takes two operands. It applies AND operation on each bit of value.
Example:
void main()
{
int a= 10, b=12, c;
c=a&, b;
printf (“%d”, c);
}
Output:
c=8
a —  1 0 1 0
&
b —  1 1 0 0
—————–
c —  1 0 0 0

#### | (Bitwise OR):

• | is known as the Bitwise OR. This operator takes two operands. It performs OR operation on each bit of the value.
Example:
void main()
{
int a=10, b=12, c;
/ c=a/ b;
printf (“%d”, c);
}
Output:
c=14
a —  1 0 1 0
|
b —  1 1 0 0
—————–
c —  1 1 1 0

#### ^ (Bitwise exclusion OR):

• ^ is known as the Bitwise exclusive OR. This operator takes operads. It performs exclusive OR operation on each bit of values.
Example:
void main()
{
int a=10, b=12, c;
c=a / b;
printf (“%d”, c);
}
Output
c = 6
a —  1 0 1 0
^
b —  1 1 0 0
—————–
c —  0 1 1 0

### Sizeof Operator

• In our program, at any instance, we may want to find the bytes occupied by the operand.
• To do this, C provides the operator called sizeof, ” sizeof is the operator which is used to return the number of bytes occupied by the operand.”

#### The operand may be a variable, constant of a data type.

Example:
int a, arr;
float f, ff;
printf(“%d %d %d %d”, sizeof(arr), sizeof(f), sizeof(ff), sizeof(chart):

Output:
2 20 4 40 1

Last updated on Sunday - May 21st, 2023

.