Skip to content

Instantly share code, notes, and snippets.

@TommyJerryMairo
Created January 10, 2018 00:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TommyJerryMairo/38f0ca2f29494249fb5abc6f29aa28f5 to your computer and use it in GitHub Desktop.
Save TommyJerryMairo/38f0ca2f29494249fb5abc6f29aa28f5 to your computer and use it in GitHub Desktop.
#include<iostream>
#include<cstdio>
using namespace std;
int main(int argc, char * argv[]){
if(2==argc){
int x = atoi(argv[1]);
cout << "Origional: " << x << endl;
//cout << "Big-endian: " << hex << uppercase << x << endl;
printf("Big-endian: %#010X\n",x);
int s=0;
for(int i=0;i<4;i++){
int byte=x&0xff;
int shifted=byte<<(3-i)*8;
s|=shifted;
x>>=8;
}
//cout << "Little-endian: " << hex << uppercase << s << endl;
printf("Little-endian: %#010X\n",s);
cout << "Converted: " << s << endl;
} else{
cerr << "usage: " << argv[0] << " integer" << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment