Wednesday - June 7, 2023

What is Bitwise operators in C

Bitwise 2Boperators

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.
bitwise operators python, bitwise operators java, bitwise operators c, bitwise operators javascript, bitwise operators can operate upon, bitwise and, bitwise operators calculator, bitwise operators in c hackerrank solution, bitwise operators python, bitwise operators java, bitwise and calculator, bitwise operators - javascript, bitwise operators c#, bitwise operators in c hackerrank solution, bitwise calculator, 1 2 result, logical xor in c, bitwise operator in c with example, php bitwise operators, php xor string, php string to binary, operator php,
Image Source ~ Crafted With ©Ishwaranand – 2020 ~ Image by ©Ishwaranand
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[10];
float f, ff[10];
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

What is Bitwise operators in C

What is Operators in C

.