Created
October 12, 2014 15:44
-
-
Save caigen/e90f33b18f65bf8e81ec to your computer and use it in GitHub Desktop.
32bit-64bit small-endian big-endian
This file contains 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> | |
int main(int argc, char* argv[]) { | |
std::cout << sizeof(void *) << std::endl; | |
std::cout << sizeof(int *) << std::endl; | |
std::cout << sizeof(double *) << std::endl; | |
int* p = 0x0; | |
p++; | |
if (p == (int *)0x4) { | |
std::cout << "32 bit" << std::endl; | |
} | |
// 0x01 0x02 0x03 0x04 | |
// | |
union { | |
int i; | |
char c; | |
} x; | |
x.i = 0x87654321; | |
if (x.c == 0x87) { | |
std::cout << "big endian" << std::endl; | |
} | |
else if (x.c == 0x21) { | |
std::cout << "small endian" << std::endl; | |
} | |
int xx = 0x87654321; | |
char c = *(char *)&xx; | |
std::cout << (int)c << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment