简体   繁体   中英

Java get hex reversed

I'm trying to read a file like that:

private File infile;
private FileInputStream fis;
private DataInputStream dis;

and

infile = new File("myfile");
fis = new FileInputStream(infile);
dis = new DataInputStream(fis);

Now I want to read a hex like that:

int current = dis.readInt();
System.out.println("0x" + Integer.toHexString(current));

For anybody who needs it: here are the first bytes of my file

3412 aa55 0200 0000

The problem is that my output is 0x3412aa55 but it should be 0x55aa1234 . What can I do to fix this?

使用Integer.reverseBytes()反转字节。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM