Sunday, January 15, 2012

Little endian to big endian

//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)+((i&0xff0000)>>8)+((i>>24)&0xff);
}

No comments: