#include<bits/stdc++.h> using namespace std; int main() { int n,m; cout<<"Please enter the number"; cin>>n; cout<<"please enter the bit u want to manipulate"; cin>>m; cout<<"we are printing all the bits in this number"; int bits = sizeof(n) * 4; for(int i=bits-1;i>=0;i--) { int bit = (n>>i)&1; cout<<bit; } cout<<endl; cout<<"now we want to manipulate bit"; n = n^(1<<m); cout<<"the main vlue "<<n<<endl; for(int i=bits-1;i>=0;i--) { int bit = (n>>i)&1; cout<<bit; } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter