Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Explore endianness.
#import <Foundation/Foundation.h>
// Xcode_3_2_6/usr/bin/gcc -arch ppc -std=c99 -isysroot /Xcode_3_2_6/SDKs/MacOSX10.5.sdk -g -Wall -framework Foundation -o endian-ppc ~/Downloads/endian.m (thanks to Jeremy W. Sherman for the assist)
// clang -arch x86_64 -g -Weverything -framework Foundation -o endian endian.m
int main (void) {
unsigned int values[] = { 1, 387, 8533937 };
printf ("scan by ints\n");
for (unsigned int i = 0; i < sizeof(values) / sizeof(*values); i++) {
printf (" 0x%08x", values[i]);
}
printf ("\n");
printf ("scan by bytes\n");
for (unsigned int i = 0; i < sizeof(values); i++) {
if (i % 4 == 0) printf (" 0x");
printf ("%02x", ((unsigned char *)values)[i]);
}
printf ("\n");
return 0;
} // main
#if 0
Outputs:
scan by ints
0x00000001 0x00000183 0x008237b1
scan by bytes
0x01000000 0x83010000 0xb1378200
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment