public static int ByteArrayToint(byte[] b)
{
//byte[] b=new byte[]{1,2,3,4};
int mask = 0xff;
int temp = 0;
int res = 0;
for(int i=0;i<4;i++)
{
res<<=8;
temp = b[i]&mask;
res |= temp;
}
return res;
}
大端可以这样转化小端应该怎么做?
{
//byte[] b=new byte[]{1,2,3,4};
int mask = 0xff;
int temp = 0;
int res = 0;
for(int i=0;i<4;i++)
{
res<<=8;
temp = b[i]&mask;
res |= temp;
}
return res;
}
大端可以这样转化小端应该怎么做?
解决方案 »
- 数组对象 和对象数组分别指什么?
- 执行sql server 存储过程 是不是这样,怎么不对啊。
- 弹出窗口问题(拜托个位高人了,急!!!)
- 如何实现将一个客户端发送的命令或者脚本,在服务端接受并将其结果返回到客户端
- 刚学Java,问一个很初浅的问题
- 关于继承下的构造函数和finalize方法的问题,高手请进!
- 新手求助:java中的复制与粘贴
- ™符号如何在java applet中显示
- 揭晓一下IBM那道题的答案,顺便再出一道,^_^
- 更新数据库的字段值,为什么总是为乱码?
- JTable刷新
- 【帮忙挑错】Spring aop调试中的Cast错误(Exception in thread "main" java.lang.ClassCastException: aop.co.jp.MyAro)
public class TestByte {
public static void main(String args[]) {
byte[] b=TestByte.getbytes("01000000");
ByteBuffer bb = ByteBuffer.wrap(b);
int temp = bb.getInt();
System.out.println(temp);
System.out.println(Integer.reverseBytes(temp)); }
// 16进制字符串转byte[]
public static byte[] getbytes(String data) {
int len = data.length();
byte[] ba = new byte[len / 2];
int i = 0, j = 0, c;
while (i < len) {
c = Character.digit(data.charAt(i++), 16) << 4;
c = c + Character.digit(data.charAt(i++), 16);
ba[j++] = (byte) c;
}
return ba;
}