62,620
社区成员
发帖
与我相关
我的任务
分享long l = (long) Integer.MIN_VALUE;
补充:输入为大端序byte[],但是需要表示为无符号数,java不支持
目前考虑的方法是:
InputStream is = new DataInputStream(new ByteArrayInputStream(buf));
byte[] bb = new byte[2]; // 针对byte
byte[] bs = new byte[4]; // 针对short
byte[] bi = new byte[8]; // 针对int
is.read(bb, 1, 1);
is.read(bs, 2, 2);
is.read(bi, 4, 4);
short s = new BigInteger(bb).shortValue(); // byte -> short
int i = new BigInteger(bs).intValue(); // short -> int
long l = new BigInteger(bi).longValue(); // int -> long
土?还有更简洁的方法吗?