Here you can find the source of convertLong(byte[] data, int offset)
Parameter | Description |
---|---|
data | the byte[] that stores the Integer of interest |
offset | the offset into the data[] |
public static long convertLong(byte[] data, int offset)
//package com.java2s; //License from project: Open Source License public class Main { /**/* ww w. j a v a 2 s. c o m*/ * This method uses a leading 1 byte[] * This method converts a 4 byte int to a decimal int * @param data a byte[] storing a 4 byte int * @return a decimal Integer that is equal to the byte[] integer */ public static long convertLong(byte[] data) { long value = 0; for (int i = 0; i < data.length; i++) { value = (value << 8) + (data[i] & 0xff); } return value; } /** * This method uses a leading 1 byte[] * This method converts a 4 byte integer that is stored in a byte[] and converts it to a decimal int * @param data the byte[] that stores the Integer of interest * @param offset the offset into the data[] * @return a decimal Integer that is equal to the byte[] integer */ public static long convertLong(byte[] data, int offset) { byte[] target = new byte[4]; System.arraycopy(data, offset, target, 0, target.length); return convertLong(target); } }