/*Program to convert between endianess*/
/*Author Brijoo Bopannna*/
unsigned int endian ( unsigned x )
{
unsigned invert ;
const unsigned char *xp = (const unsigned char *) &x;
unsigned char *pIp = (unsigned char * ) & invert;
//Why is the above type cast required????
pIp [0] = xp [3]; /* reverse the individual bytes */
pIp [1] = xp [2];
pIp [2] = xp [1];
pIp [3] = xp [0];
return invert ; /* return the bytes reversed */
}
Tuesday, April 3, 2007
Subscribe to:
Posts (Atom)
