Java获得十六进制反转
我正在尝试读取这样的文件:Java获得十六进制反转,java,file-io,hex,datainputstream,Java,File Io,Hex,Datainputstream,我正在尝试读取这样的文件: private File infile; private FileInputStream fis; private DataInputStream dis; 及 现在我想读一个十六进制: int current = dis.readInt(); System.out.println("0x" + Integer.toHexString(current)); 对于任何需要它的人:这里是我的文件的第一个字节 3412 aa55 0200 0000 问题是我的输出是0x
private File infile;
private FileInputStream fis;
private DataInputStream dis;
及
现在我想读一个十六进制:
int current = dis.readInt();
System.out.println("0x" + Integer.toHexString(current));
对于任何需要它的人:这里是我的文件的第一个字节
3412 aa55 0200 0000
问题是我的输出是
0x3412aa55
,但它应该是0x55aa1234
。我能做些什么来解决这个问题呢?使用Integer.reverseBytes()
来反转字节。使用Integer.reverseBytes()
来反转字节。你是说like Integer.tohextString(Integer.reverse(current))?不,这会给我0xAA55482明白了,我用reverse()而不是reverseBytes(),你的意思是like Integer.tohextString(Integer.reverse(current))?不,这将给我0xAA55482。我使用了reverse()而不是reverseBytes()
int current = dis.readInt();
System.out.println("0x" + Integer.toHexString(current));