Here you can find the source of byte2long(byte[] b)
Parameter | Description |
---|---|
b | a parameter |
public static long byte2long(byte[] b)
//package com.java2s; public class Main { /**/*from ww w.ja va2 s .c om*/ * Converts byte representation to long. * Maximal byte size is 4. * * 1st byte in b[0] is mapped to LSB in long. * * @param b * @return */ public static long byte2long(byte[] b) { return ((long) b[0] & 0xff) | (((long) b[1] & 0xff) << 8) | (((long) b[2] & 0xff) << 16) | (((long) b[3] & 0xff) << 24); } /** * Converts byte representation to long form on given position - by idx. * Can be used multiple times on same long and OR results together. * * LSB in long will be 1st bit in byte[0]. * @param a * @param idx * @return */ public static long byte2long(byte a, int idx) { return (long) ((long) (a & 0xff) << (8 * idx)); } }