C4U

The output of bitwise AND is 1 if the corresponding bits of all operands is 1. If either bit of an operand is 0, the result of corresponding bit is evaluated to 0.

12 = 00001100 (In Binary)

25 = 00011001 (In Binary)

00001100

& 00011001

________

00001000 = 8 (In decimal)

#include < stdio.h>

int main()

{

int a = 12, b = 25;

printf("Output = %d", a&b);

return 0;

}

Output = 8

The output of bitwise OR is 1 if at least one corresponding bit of two operands is 1. In C Programming, bitwise OR operator is denoted by

12 = 00001100 (In Binary)

25 = 00011001 (In Binary)

00001100

| 00011001

________

00011101 = 29 (In decimal)

#include < stdio.h>

int main()

{

int a = 12, b = 25;

printf("Output = %d", a|b);

return 0;

}

Output = 29

The result of bitwise XOR operator is 1 if the corresponding bits of two operands are opposite. It is denoted by

12 = 00001100 (In Binary)

25 = 00011001 (In Binary)

Bitwise XOR Operation of 12 and 25

00001100

| 00011001

________

00010101 = 21 (In decimal)

#include < stdio.h>

int main()

{

int a = 12, b = 25;

printf("Output = %d", a^b);

return 0;

}

Output = 21

Bitwise compliment operator is an unary operator (works on one operand only). It changes the 1 to 0 and 0 to 1. It is denoted by

35=00100011 (In Binary)

Bitwise complement Operation of 35

~ 00100011

________

11011100 = 220 (In decimal)

int a=11,b=6,c;

c=a&b; c=2

a=1011

b=0110

c=0010

int a=11,b=6,c;

c=a|b; c=20

a=1011

b=0110

c=1111

int a=11,c; c=a>>1; a=1011

c=0101

c=5;

int a=11,c; c=a<<1; a=1011

c=10110

c=22;