Created
January 10, 2018 00:45
-
-
Save TommyJerryMairo/38f0ca2f29494249fb5abc6f29aa28f5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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