Convert byte array to Long by offset - Android File Input Output

Android examples for File Input Output:Byte Array Convert

Description

Convert byte array to Long by offset

Demo Code


//package com.java2s;

public class Main {
    public static long bytestoLong(byte[] b, int off) {

        return ((((long) b[0 + off] & 0xff) << 56)
                | (((long) b[1 + off] & 0xff) << 48)
                | (((long) b[2 + off] & 0xff) << 40)
                | (((long) b[3 + off] & 0xff) << 32)

                | (((long) b[4 + off] & 0xff) << 24)
                | (((long) b[5 + off] & 0xff) << 16)
                | (((long) b[6 + off] & 0xff) << 8) | (((long) b[7 + off] & 0xff) << 0));
    }/*from  w  ww .j a v  a 2  s  .  c om*/
}

Related Tutorials