C Bitwise operators

Previous
Next

Bitwise 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.

ABA&BA|BA^B
00000
01011
10011
11110
#include<stdio.h>
int 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);
	return 0;
}

Output this:

#include<stdio.h>
int 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);
	return 0;
}
Previous
Next

Add Comment

Courses Enquiry Form