byte To Uint 8 - Java java.lang

Java examples for java.lang:byte Array to int

Description

byte To Uint 8

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(byteToUint8(input,offset));
    }//w  w  w . j  av a  2s. co m
    public static BigInteger byteToUint8(byte[] input, int offset) {
        return byteToUint8(input, offset, 8);
    }
    public static BigInteger byteToUint8(byte[] input, int offset, int len) {
        BigInteger num = BigInteger.ZERO;

        for (int i = offset; i < (offset + len); i++) {
            BigInteger n = new BigInteger(
                    Integer.toString((input[i] & 0x000000ff) << (i * 8)));
            num = num.or(n);
        }

        return num;
    }
}

Related Tutorials