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.

Advertisements
This entry was posted in Game Programing and tagged . Bookmark the permalink.

One Response to Is little endian or big endian?

  1. SquidMan says:

    Wow, that’s a really neat trick. I never thought of that before. I’ll have to find a use for that some time 😀

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s