Java Byte Array to Int byteToInt(byte[] b)

Here you can find the source of byteToInt(byte[] b)

Description

byte To Int

License

Apache License

Parameter

Parameter Description
b a parameter

Declaration

public static int byteToInt(byte[] b) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/*from w  ww.  j av  a  2  s . c  o m*/
     * @param b
     * @return
     */
    public static int byteToInt(byte[] b) {
        int s = 0;
        final int n256 = 256;
        final int n2 = 2;
        for (int i = 0; i < n2; i++) {
            s = s * n256;
            if (b[i] >= 0) {
                s = s + b[i];
            } else {
                s = s + n256 + b[i];
            }
        }
        return s;
    }
}

Related

  1. bytesToInts(byte[] a, int ao, int[] b, int bo, int len)
  2. bytesToInts(byte[] bytes, int shift, int[] spec)
  3. bytesToInts(byte[] data)
  4. bytesToInts(byte[][] bytes)
  5. byteToInt(byte b[])
  6. byteToInt(byte[] b)
  7. byteToInt(byte[] bank)
  8. byteToInt(byte[] buf, int off)
  9. byteToInt(byte[] byteArray)