Thursday, January 24, 2008

Is little endian or big endian?

I saw interesting code to check endian.

bool isLittle()
unsigned int val = 1;
return *((unsigned char *)&val);

If a machine is little-endian, 'val' is reversed and stored to a memory. That may be implementation-dependent way. But I think that it isn't problem for specific products, if the library having the check code supports specific type of applications.

Of course, if this value is not cached, we should use const.

1 comment:

Anonymous said...

it's better if u have mentioned wot language is this code..