Bit-Wise Operators in C Language

This Bit wise Operators in C Language post explains about all the available bit wise operators, their functionality , priority with suitable examples.


 

Bit-wise Operators:

  • Bitwise operators are used to manipulate the data at bit level.

  • They can be applied only to char and int types.

  • The operators are

Bitwise – AND (&)
Bitwise – OR (|)
Bitwise – XOR(^)

 

  • These operators first convert the data into corresponding binary form and then perform the operations according to truth table.

 

Truth table:
a         b        a&b       a|b        a^b
0         0          0          0           0
0         1          0          1           1
1         0          0          1           1
1         1          1          1           0

 

#include<stdio.h>
main()
{
    int a=15,b=8,c,d,e;
    c = a & b ;
    d = a | b ;
    e = a ^ b ;
    printf(“%d,%d,%d”,c,d,e);
}

#include<stdio.h>
main()
{
    int i=32, j=0x20, k, l, m;
    k=i|j;
    l=i&j;
    m=k^l;
    printf(“%d, %d, %d, %d, %d\n”, i, j, k, l, m);
}

#include<stdio.h>
main()
{
    int i=4, j=8;
    printf(“%d, %d, %d\n”, i|j&j|i,i|j&&j|i, i^j);
}

Share this