Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***
- Bismillahir Rahmanir Rahim
- _______
- | __ \ _____
- | |__| )_______ | / ____ ______
- | ____/ \__ \ | |__ / \ | \
- | ( / __ \ | __ \ / __ \ | /\ \
- | | (____ / | / \ / |__/ \ )
- |__| \/ |____/ \____/ \/
- ***/
- #include<bits/stdc++.h>
- using namespace std;
- bool check(int num,int pos)
- {
- return num & (1<<pos);
- }
- int biton(int num,int pos)
- {
- return num|=(1<<pos);
- }
- int bitoff(int num,int pos)
- {
- return num &= ~(1<<pos);
- }
- int main()
- {
- int number,pos;
- cout<<"Enter a Number please : ";
- while(cin>>number)
- {
- cout<<"\nPosition is : ";
- cin>>pos;
- cout<<"\nThe "<<pos<<"'th bit is : "<<check(number,pos)<<"\n\n";
- if(check(number,pos))
- {
- cout<<"\nThe "<<pos<<"'th bit is already On\n\n";
- }
- else
- {
- cout<<"\nNow the "<<pos<<"'th bit is On";
- cout<<" and Changed Number is : "<<biton(number,pos)<<"\n\n";
- }
- if(check(number,pos))
- {
- cout<<"\nNow the "<<pos<<"'th bit is Off";
- cout<<" and Changed Number is : "<<bitoff(number,pos)<<"\n\n";
- }
- else
- {
- cout<<"\nThe "<<pos<<"'th bit is already Off\n\n";
- }
- cout<<"\n______________\n";
- cout<<"\nEnter a Number please : ";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment