Skip to content

Instantly share code, notes, and snippets.

@rainyear
Created July 20, 2014 15:25
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 rainyear/19d9c938c98039677f9b to your computer and use it in GitHub Desktop.
Save rainyear/19d9c938c98039677f9b to your computer and use it in GitHub Desktop.
Show bytes and check which endian the machine is.
#include <stdio.h>
typedef unsigned char* byte_ptr;
void show_bytes(byte_ptr start, int len){
for(int i = 0; i < len; i++)
printf("\t%.2x", start[i]);
printf("\n");
}
int main(){
int i = 0x1234567;
show_bytes((byte_ptr) &i, sizeof(i));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment