Bitwise Calculation In C Programming

Here is an example of bitwise calculation using bitwise AND, OR, XOR, 1's Complement
Code goes like this :

/* Program using bitwise AND, OR, XOR and 1's Complement operator */
#include<stdio.h>
int main()
{
int a, b;
printf("Enter two numbers : ");
scanf("%d %d",&a, &b);
printf("\n Bitwise AND calculation %d\n",a&b);                          // bitwise AND &
printf("\n Bitwise OR calculation %d\n",a|b);                      // bitwise OR |
printf("\n Bitwsie XOR calculation %d\n",a^b);                      //bitwise XOR ^
printf("\n Bitwsie 1\'s Complement calculation %d\n",b=~a);        //bitwise 1's complement
return 0;
}

Output :

















I have used Dev CPP to compile this program.
If you are using Turbo C++ IDE, then use conio.h in link section after stdio.h
and use getch(); to hold the output screen, just before the end of main function.
If you have any confusion regarding the program, please, comment below.
Happy Coding !
Thank you.
Share on Google Plus

About Nepali Xoro

Interested in Information Technology, Spreading Knowledge for Nepalease IT Students."Loves Traveling", Listen Music and Surfing web.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment