byte[] bytes = new byte[]{(byte) 19, (byte) 247, (byte) 11};
System.out.println("for循环:");
int iooo = 0;
for (int j = 0; j < bytes.length; j++) {
iooo = iooo | (bytes[j] & 0xFF) << (bytes.length - j - 1) * 8;
}
System.out.println(iooo);
System.out.println(Integer.toBinaryString(iooo));
System.out.println("拼接:");
int i1 = (bytes[0] & 0xFF) << 16 | (bytes[1] & 0xFF) << 8 | bytes[2] & 0xFF;
System.out.println(i1);
System.out.println(Integer.toBinaryString(i1));
System.out.println("BigInteger:");
BigInteger bigInteger = new BigInteger(1, bytes);
System.out.println(bigInteger.toString(10));
System.out.println(bigInteger.toString(2));
输出:
for循环:
1308427
100111111011100001011
拼接:
1308427
100111111011100001011
BigInteger:
1308427
100111111011100001011
网友评论