Skip to content

Instantly share code, notes, and snippets.

@meritozh
Created October 20, 2016 14:47
Show Gist options
  • Save meritozh/38a269df2ae5485d474bbd91011b93e3 to your computer and use it in GitHub Desktop.
Save meritozh/38a269df2ae5485d474bbd91011b93e3 to your computer and use it in GitHub Desktop.
little endian and big endian
#include <netinet/in.h>
#include <stdio.h>
int main(int argc, const char *argv[]) {
int i = 1093173256;
int k = htonl(i);
printf("%d %d\n", i, k);
return 0;
}
@meritozh
Copy link
Author

In a intel CPU platform, it will print 1093173256 142616641.

oct -> hex:

41 28 80 08 08 80 28 41

It means:

little endian:
| byte3 | byte2 | byte1 | byte0 |

big endian
| byte0 | byte1 | byte2 | byte3 |

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment