I used to recommend MacOSX as bi-endian platform that is easiest to work with. But Snow Leopard is the version that officially supports bi-endianness and the hardware to run it is getting hard to come by.
I'm going to post a short demonstration program that is probably a quickest way to convince the wondering programmer that Bitcoin protocol is neither big-endian nor little-endian.
To compile use the following command on Mac OSX 10.[56]:
union mojibake {
unsigned char b[32],
b1[32][1],b2[16][2],b4[8][4],
b8[4][8],b16[2][16],b32[1][32];
unsigned short h[16];
unsigned int w[8];
unsigned long long d[4];
} x;
#if defined(__LITTLE_ENDIAN__) || defined(_MSC_VER)
#define E(N,j) (N-1-(j))
#elif defined(__BIG_ENDIAN__)
#define E(N,j) (j)
#else
#error not tested under this compiler
#endif
#define NL putchar('\n')
#define P(N) \
for (i = 0; i < 32/N; ++i) { \
printf("%*c",N,' '); \
for (j = 0; j < N; ++j) \
printf("%02x",x.b##N[i][E(N,j)]); \
} \
NL,NL
int main(int ac,char **av)
{
int i,j;
if (ac < 2)
ugh: return printf("usage: %s
"where:
" for l)ittle endian\n"
" or b)ig endian\n"
" or m)ojibake endian\n",av[0]);
switch (av[1][0]) {
case 'l': case 'L':
for (i = 0; i < sizeof x; ++i)
x.b[i] = i;
break;
case 'b': case 'B':
for (i = 0; i < sizeof x; ++i)
x.b[(sizeof x - 1) - i] = i;
break;
case 'm': case 'M':
for (i = 0; i < sizeof x; ++i)
x.b4[7-i/4][i%4] = i;
break;
default:
goto ugh;
}
for (i = 0; i < sizeof x; ++i)
printf("%1c%02x",' ',x.b[i]);
NL,NL;
for (i = 0; i < sizeof x/sizeof(short); ++i)
printf("%2c%04x",' ',x.h[i]);
NL,NL;
for (i = 0; i < sizeof x/sizeof(int); ++i)
printf("%4c%08x",' ',x.w[i]);
NL,NL;
for (i = 0; i < sizeof x/sizeof(long long); ++i)
printf("%8c%016llx",' ',x.d[i]);
NL,NL;
/*
P(2);
P(4);
*/
P(8);
P(16);
P(32);
return 0;
}
00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f
0100 0302 0504 0706 0908 0b0a 0d0c 0f0e 1110 1312 1514 1716 1918 1b1a 1d1c 1f1e
03020100 07060504 0b0a0908 0f0e0d0c 13121110 17161514 1b1a1918 1f1e1d1c
0706050403020100 0f0e0d0c0b0a0908 1716151413121110 1f1e1d1c1b1a1918
0706050403020100 0f0e0d0c0b0a0908 1716151413121110 1f1e1d1c1b1a1918
0f0e0d0c0b0a09080706050403020100 1f1e1d1c1b1a19181716151413121110
1f1e1d1c1b1a191817161514131211100f0e0d0c0b0a09080706050403020100
$ arch -i386 ./mojibake b
1f 1e 1d 1c 1b 1a 19 18 17 16 15 14 13 12 11 10 0f 0e 0d 0c 0b 0a 09 08 07 06 05 04 03 02 01 00
1e1f 1c1d 1a1b 1819 1617 1415 1213 1011 0e0f 0c0d 0a0b 0809 0607 0405 0203 0001
1c1d1e1f 18191a1b 14151617 10111213 0c0d0e0f 08090a0b 04050607 00010203
18191a1b1c1d1e1f 1011121314151617 08090a0b0c0d0e0f 0001020304050607
18191a1b1c1d1e1f 1011121314151617 08090a0b0c0d0e0f 0001020304050607
101112131415161718191a1b1c1d1e1f 000102030405060708090a0b0c0d0e0f
000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f
$ arch -i386 ./mojibake m
1c 1d 1e 1f 18 19 1a 1b 14 15 16 17 10 11 12 13 0c 0d 0e 0f 08 09 0a 0b 04 05 06 07 00 01 02 03
1d1c 1f1e 1918 1b1a 1514 1716 1110 1312 0d0c 0f0e 0908 0b0a 0504 0706 0100 0302
1f1e1d1c 1b1a1918 17161514 13121110 0f0e0d0c 0b0a0908 07060504 03020100
1b1a19181f1e1d1c 1312111017161514 0b0a09080f0e0d0c 0302010007060504
1b1a19181f1e1d1c 1312111017161514 0b0a09080f0e0d0c 0302010007060504
13121110171615141b1a19181f1e1d1c 03020100070605040b0a09080f0e0d0c
03020100070605040b0a09080f0e0d0c13121110171615141b1a19181f1e1d1c
00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f
0001 0203 0405 0607 0809 0a0b 0c0d 0e0f 1011 1213 1415 1617 1819 1a1b 1c1d 1e1f
00010203 04050607 08090a0b 0c0d0e0f 10111213 14151617 18191a1b 1c1d1e1f
0001020304050607 08090a0b0c0d0e0f 1011121314151617 18191a1b1c1d1e1f
0001020304050607 08090a0b0c0d0e0f 1011121314151617 18191a1b1c1d1e1f
000102030405060708090a0b0c0d0e0f 101112131415161718191a1b1c1d1e1f
000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f
$ arch -ppc ./mojibake b
1f 1e 1d 1c 1b 1a 19 18 17 16 15 14 13 12 11 10 0f 0e 0d 0c 0b 0a 09 08 07 06 05 04 03 02 01 00
1f1e 1d1c 1b1a 1918 1716 1514 1312 1110 0f0e 0d0c 0b0a 0908 0706 0504 0302 0100
1f1e1d1c 1b1a1918 17161514 13121110 0f0e0d0c 0b0a0908 07060504 03020100
1f1e1d1c1b1a1918 1716151413121110 0f0e0d0c0b0a0908 0706050403020100
1f1e1d1c1b1a1918 1716151413121110 0f0e0d0c0b0a0908 0706050403020100
1f1e1d1c1b1a19181716151413121110 0f0e0d0c0b0a09080706050403020100
1f1e1d1c1b1a191817161514131211100f0e0d0c0b0a09080706050403020100
$ arch -ppc ./mojibake m
1c 1d 1e 1f 18 19 1a 1b 14 15 16 17 10 11 12 13 0c 0d 0e 0f 08 09 0a 0b 04 05 06 07 00 01 02 03
1c1d 1e1f 1819 1a1b 1415 1617 1011 1213 0c0d 0e0f 0809 0a0b 0405 0607 0001 0203
1c1d1e1f 18191a1b 14151617 10111213 0c0d0e0f 08090a0b 04050607 00010203
1c1d1e1f18191a1b 1415161710111213 0c0d0e0f08090a0b 0405060700010203
1c1d1e1f18191a1b 1415161710111213 0c0d0e0f08090a0b 0405060700010203
1c1d1e1f18191a1b1415161710111213 0c0d0e0f08090a0b0405060700010203
1c1d1e1f18191a1b14151617101112130c0d0e0f08090a0b0405060700010203