Problem:
Please find the problem here.
Solution:
This is the simplest problem I ever had, just implement the given formulas! However, it does take me some time to write.
Hint: swaping the character pointer for each bits reverses the entire byte. And displaying the value after reversal.
Code:
#include<bits/stdc++.h>
using namespace std;
#define swp(a,b) a=a^b, b=a^b, a=a^b
main(){
int n,reverse;
while(cin>>n){
reverse =n;
char* bits =(char*) &reverse;
swp(bits[0],bits[3]);
swp(bits[1],bits[2]);
cout<<n<<" converts to "<<reverse<<endl;
}
}
No comments:
Post a Comment