Bitwise AND Operator in C programming Language
Bitwise Operators in C :
 Bitwise AND Operator is denoted with ‘&’
 Bitwise AND is Binary operator i.e it operates on two operands.
 bitwise operators, operates on bits ( not Bytes). Logical AND ( && ) operator operates on Bytes.
Let us take a Example to understand difference between Logical AND Operator and Bitwise AND Operator.
A = 20 and B = 10. Both are Integers.
Logical AND ( && ) Operation :
A && B ;
20 && 10 ;
result is 1
because logical AND output is one if the both inputs are nonzero here inputs are 10 and 20 and both are nonzero so output of AND is one.
Bitwise AND ( & ) Operation :
A & B ;
20 & 10 ;
but unlike Logical AND, bitwise AND operates on bit level.
here A and B are integer data. size of integer is 4 byes i.e 32 bits so we need to compare these 32 bits sequences of A and B ( because bitwise AND Operates on bits).
A ( 20 ) Binary Representation is 0000 0000 0001 0100
B ( 10 ) Binary Representation is 0000 0000 0000 1010
The Truth table for AND is as shown below :
Input 1

Input 2

Output

0

0

0

0

1

0

1

0

0

1

1

1

From the truth table it is clear bitwise operator output is one only if the two inputs are one, otherwise output is Zero.
Let us apply bitwise AND on our Example A & B that is 20 & 10
0000 0000 0001 0100 ( =20 )
& 0000 0000 0000 1010 ( =10 )
————————
0000 0000 0000 0000 ( =0 )
————————
Result of A & B is zero.
From above example it is clear that logical AND operator (or all Logical Operators) operates on Byte level. But Bitwise operators are Operates on Bit Level.
C Program to Understand Bitwise AND Operator :

#include <stdio.h>

int main(void)

{

int A,B;

A=20;

B=10;

printf(“Logical AND of A,B is A&&B : %d n“,A&&B);

printf(“Bitwise AND of A,B is A&B : %d n“,A&B);

return 0;

}
Output :
Logical AND of A,B is A&&B : 1
Bitwise AND of A,B is A&B : 0
Related Posts :
 Compilation Stages in Computer Programming.
 Arithmetic Operators with Examples.
 Arithmetic operators priority and it’s Associativity.
 Modulus Operator and Hidden Concepts of Modulus Operator.
 Precedence Table or Operators Priority Table.
 Assignment Operator, Usage, Examples
 Increment Operator and Different types of Increment operators Usage with Examples.
 Decrement Operator and Different types of Decrement operators with Examples.
 Logical Operators tutorial with Examples.
 Relational Operators Tutorial with Examples.
 Conditional Operator tutorial and In depth analysis.
 Bitwise operators Tutorial.
 Comma Operator Tutorial
1 Response
[…] Bitwise AND( & ) […]