//{ Driver Code Starts #include <bits/stdc++.h> using namespace std; // } Driver Code Ends class Solution { public: int getbit(int num1 , int j) { if((num1>>j-1)&1) { return 1; } else{ return 0; } } int setbit(int num1 , int j) { num1 = num1|(1<<j-1); return num1 ; } int clearbit(int num1 , int j ) { num1 = num1&~(1<<j-1); return num1; } void bitManipulation(int num, int i) { // your code here //get the bit int num1 = num; int j = i; cout<<getbit(num1 , j); cout<<" "<<setbit(num1, j); cout<<" "<<clearbit(num1 , j); } }; //{ Driver Code Starts. int main() { int t; cin >> t; while (t--) { int n, i; cin >> n >> i; Solution ob; ob.bitManipulation(n, i); cout << "\n"; cout << "~" << "\n"; } return 0; } // } Driver Code Ends
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