convert little Endian file into big Endian

后端 未结 6 887
感动是毒
感动是毒 2020-12-04 01:23

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

6条回答
  •  眼角桃花
    2020-12-04 02:18

    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));
    }
    

提交回复
热议问题