Android Byte Array to Int Convert toInt(byte[] bytes)

Here you can find the source of toInt(byte[] bytes)

Description

to Int

Declaration

public static int toInt(byte[] bytes) 

Method Source Code

//package com.java2s;

public class Main {

    public static int toInt(byte[] bytes) {
        int result = 0;
        int base = 1;

        for (int i = bytes.length - 1; i >= 0; i--) {
            result = result + (toInt(bytes[i]) * base);
            base = base * 256;/*from   www.java2  s.  c  o  m*/
        }

        return result;
    }

    public static int toInt(byte b) {
        int result = b;

        if (result < 0) {
            result = result + 256;
        }

        return result;
    }
}

Related

  1. byte2int(byte[] b)
  2. byteArray2Int(byte[] bs)
  3. byteArrayToInt(byte[] b)
  4. toIntegerArray(byte[] input, int offset, int len)
  5. toIntegerArray(byte[] input, int offset, int len, int[] output, int outputOffset)
  6. toInteger(byte[] input)
  7. toInteger(byte[] input, int offset)
  8. readInt(byte[] buff, int pos)
  9. getShort(byte[] data)