2006年9月17日星期日

Big-endian & Little-edian Detecting

A sample illustrate the differences between Big-endian and Little-endian:

Consider the number 1025 (2 to the tenth power plus one) stored in a 4-byte integer:

00000000 00000000 00000100 00000001
AddressBig-Endian representation of 1025 Little-Endian representation of 1025
00
01
02
03
00000000
00000000
00000100
00000001
00000001
00000100
00000000



A simple program for endianess detecting:

#include <stdio.h>

int main()
{
int x=1;
if (*((char *)&x)==1)
printf("Little endian.\n");
else
printf("Big endian.\n");

return 0;
}

More about endianess, referer to wikipedia/Endianness

没有评论: