The data that I am reading from a file written by another application on a different web site is wrong-endian for use in Java (I can never remember which endian is which). I can reverse the 4 bytes in an int successfully using the following code:
public static int SwapIntBytes(int i)
{
int byte0 = i & 0xff;
int byte1 = (i>>8) & 0xff;
int byte2 = (i>>16) & 0xff;
int byte3 = (i>>24) & 0xff;
// swap the byte order
return (byte0<<24) | (byte1<<16) | (byte2<<8) | byte3;
}
But when the 4 bytes are a float, I don't know how to make a similar routine that will return them as a right-endian float. I'm asking for help again. Thanks very much.
Mcklsn
public static int SwapIntBytes(int i)
{
int byte0 = i & 0xff;
int byte1 = (i>>8) & 0xff;
int byte2 = (i>>16) & 0xff;
int byte3 = (i>>24) & 0xff;
// swap the byte order
return (byte0<<24) | (byte1<<16) | (byte2<<8) | byte3;
}
But when the 4 bytes are a float, I don't know how to make a similar routine that will return them as a right-endian float. I'm asking for help again. Thanks very much.
Mcklsn