java 16进制高低位转换问题

将数据转换成16进制,可以用InteInteger.toHexString()这个方法。将16进制转换成10进制,可以用intValue()方法。高低位转换就不知道了哦。。。下面是测试代码,希望能帮到你~!public class DataTransfer { public static void main(String[] args) { // TODO Auto-generated method stub Integer a =...
java 16进制高低位转换问题
将数据转换成16进制,可以用InteInteger.toHexString()这个方法。

将16进制转换成10进制,可以用intValue()方法。

高低位转换就不知道了哦。。。

下面是测试代码,希望能帮到你~!

public class DataTransfer {

public static void main(String[] args) {
// TODO Auto-generated method stub
Integer a = -1;
System.out.println(Integer.toHexString(a));
Integer b = 0xff;
System.out.println(b.intValue());
}

}

下面这个是在网上找到的,高低位转换:

// Java读取后,顺序已经反了
int javaReadInt = ;

// 将每个字节取出来
byte byte4 = (byte) (javaReadInt & 0xff);
byte byte3 = (byte) ((javaReadInt & 0xff00) >> 8);
byte byte2 = (byte) ((javaReadInt & 0xff0000) >> 16);
byte byte1 = (byte) ((javaReadInt & 0xff000000) >> 24);

// 拼装成 正确的int
int realint = (byte1& 0xff)<<0 + (byte2& 0xff)<<8 + (byte3& 0xff)<< 16 +(byte4& 0xff)<<24 ;2010-09-21
// 将每个字节取出来
byte byte4 = (byte) (javaReadInt & 0xff);
byte byte3 = (byte) ((javaReadInt & 0xff00) >> 8);
byte byte2 = (byte) ((javaReadInt & 0xff0000) >> 16);
byte byte1 = (byte) ((javaReadInt & 0xff000000) >> 24);

// 拼装成 正确的int
int
realint = (byte1& 0xff)<<0 + (byte2&
0xff)<<8 + (byte3& 0xff)<< 16
+(byte4& 0xff)<<24 ;2015-11-14
mengvlog 阅读 12 次 更新于 2025-06-20 12:01:45 我来答关注问题0
檬味博客在线解答立即免费咨询

Java相关话题

Copyright © 2023 WWW.MENGVLOG.COM - 檬味博客
返回顶部