Play and learn 300 000+ tabs online

Wednesday, August 11, 2010

Little Endian To Big Endian Conversion

Convert "Little-Endian" to "Big-Endian"
This tip outlines two simple methods that help you to convert
a number from the "little-endian" format to the 
"big-endian" format.

// 2-byte number
int SHORT_little_endian_TO_big_endian(int i)
return ((i>>8)&0xff)+((i << 8)&0xff00);

// 4-byte number
int INT_little_endian_TO_big_endian(int i)
return((i&0xff)<<24)+((i&0xff00)<<8) +

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.