Here you can find the source of bytes2Long(byte[] bytes)
Parameter | Description |
---|---|
bytes | Big Endian |
static long bytes2Long(byte[] bytes)
//package com.java2s; //License from project: Apache License public class Main { /**/* ww w . java 2 s. c o m*/ * @param bytes Big Endian * @return */ static long bytes2Long(byte[] bytes) { return bytes2Long(bytes, 0); } /** * @param bytes Big Endian * @return */ static long bytes2Long(byte[] bytes, int offset) { int len = bytes.length - 8 >= offset ? 8 : bytes.length - offset; if (len <= 0) throw new IllegalArgumentException("offset is tow big for this byte array"); byte[] data = new byte[8]; System.arraycopy(bytes, 0, data, offset, 8); return Long.parseLong(toHex(data), 16); } static String toHex(byte[] input) { StringBuilder sb = new StringBuilder(); for (byte b : input) { int i = (b >> 4) & 0x0f; if (i > 9) { sb.append((char) (i + 55)); } else { sb.append((char) (i + 48)); } i = b & 0x0f; if (i > 9) { sb.append((char) (i + 55)); } else { sb.append((char) (i + 48)); } } return sb.toString(); } /** * if (len(input)<offset+length) throw toHex(input[offset,input.length]) * * @param input * @param offset * @param length max length * @return */ static String toHex(byte[] input, int offset, int length) { byte[] bytes = getSomeByte(input, offset, length); return toHex(bytes); } /** * @param input * @param offset * @param length * @return */ static byte[] getSomeByte(byte[] input, int offset, int length) { byte[] bytes = new byte[length]; System.arraycopy(input, offset, bytes, 0, length); return bytes; } }