Last active
May 1, 2024 09:40
-
-
Save multitudes/da102c7cec4416c6854769cdba141828 to your computer and use it in GitHub Desktop.
little endianness revealed!
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
long long y = 0xaabbccddeeff0123LL; | |
/* | |
compile the above with cc -c ctest.c | |
and open your binary editor. in VIM open the object file with | |
vim -b ctest.o | |
then :%! xxd | |
and look for the line with your variable | |
This is how it looks like on my mac m1 | |
00000180: 0000 0000 0000 0000 2301 ffee ddcc bbaa ........#....... | |
The real binary representation of my long long is | |
2301 ffee ddcc bbaa | |
little endian means the least significant byte first . Byte not bit! | |
in hex a byte is 2 digit btw... so 0x23 is the lsb. | |
On Ubuntu 22 I get the obj file to be slightly different but my variable is | |
still there | |
00000040: 2301 ffee ddcc bbaa 0055 6275 6e74 7520 #........Ubuntu | |
so here the binary is the same as on my mac | |
2301 ffee ddcc bbaa | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment