Mega Code Archive

 
Categories / C / Code Snippets
 

Bitwise operator

#include<stdio.h> main() { char j1,j2,j3; printf("enter value for j1 and j2"); scanf("%c,%c",&j1,&j2); j3 = j1 & j2; printf("\n j1 & j2 = %c",j3); j3 = j1 | j2; printf("\n j1 | j2 = %c",j3); j3 = j1 ^ j2; printf("\n i.e. j1 ^ j2 = %c",j3); j3 = ~j1; printf("\n compliment of j1 = %c",j3); j3 = j1<<2; printf("\n left shift by 2 bits j1 << 2 = %c",j3); j3 = j1>>2; printf("\n right shift by 2 bits j1 >> 2 = %c",j3); }