提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
将字节数组转换为长数组。
//package com.nowjava; /** 来 自 nowjava - 时代Java **/ public class Main { public static void main(String[] argv) throws Exception { byte[] b = new byte[] { 34, 35, 36, 37, 37, 37, 67, 68, 69 }; System.out.println(byteArrayToLong(b)); } /** * Converts a byte array to a long. * @param b - The byte array. Must be a length of at least 8. * @return The long. */ public static long byteArrayToLong(byte[] b) { return b[7] & 0xFF | (b[6] & 0xFF) << 8 | (b[5] & 0xFF) << 16 | (b[4] & 0xFF)