byte To Uint - Java java.lang

Java examples for java.lang:byte Array to int

Description

byte To Uint

Demo Code


import java.math.BigInteger;

public class Main{
    public static void main(String[] argv) throws Exception{
        byte[] input = new byte[]{34,35,36,37,37,37,67,68,69};
        int offset = 2;
        System.out.println(byteToUint4(input,offset));
    }//from  w w  w.  j a  v a2 s . c  o  m
    public static long byteToUint4(byte[] input, int offset) {
        return byteToUint4(input, offset, 4);
    }
    public static long byteToUint4(byte[] input, int offset, int len) {
        long num = 0;

        for (int i = offset; i < (offset + len); i++) {
            num |= ((input[i] & 0x000000ff) << (i * 8));
        }

        return num;

    }
}

Related Tutorials