how can i convert a liitle Endian binary file into big Endian binary file. i have a binary binary written in C and i am reading this file in Java with DataInputStream which
The two functions below swap between the endianness of a 2 and 4 bytes.
static short Swap_16(short x) {
return (short) ((((short) (x) & 0x00ff) << 8) | (((short) (x) & 0xff00) >> 8));
}
static int Swap_32(int x) {
return ((((int) (x) & 0x000000ff) << 24)
| (((int) (x) & 0x0000ff00) << 8)
| (((int) (x) & 0x00ff0000) >> 8) | (((int) (x) & 0xff000000) >> 24));
}