byte array to Long - Java java.lang

Java examples for java.lang:byte array to long

Description

byte array to Long

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        byte[] in = new byte[] { 34, 35, 36, 37, 37, 37, 67, 68, 69 };
        System.out.println(toLong(in));
    }/*from  w  ww.  j  av a2s  .  c  o  m*/

    public static long toLong(byte[] in) {
        long out = 0;
        for (int i = in.length - 1; i > 0; i--) {
            out |= in[i] & 0xff;
            out <<= 8;
        }
        out |= in[0] & 0xff;
        return out;
    }
}

Related Tutorials