I'm reading in a data file which is in little endian format and Im trying to use subroutines to convert int, float, character, etc. into big endian format. I've succeeded in converting the integers from the data file using this subroutine.
Code:
int fixint(int *fpt)
{
unsigned char B1, B2, B3, B4;
unsigned int swapper;
B4 = *fpt & 0x000000FF;
*fpt >>= 8;
B3 = *fpt & 0x000000FF;
*fpt >>= 8;
B2 = *fpt & 0x000000FF;
*fpt >>= 8;
B1 = *fpt & 0x000000FF;
*fpt >>= 8;
swapper = 0;
swapper += B4;
swapper <<= 8;
swapper += B3;
swapper <<= 8;
swapper += B2;
swapper <<= 8;
swapper += B1;
*fpt = swapper;
}
Obviously this only works for integers but I really have no idea where to start with characters or floating point numbers. lol Please help.