Java Integer Create toInt(byte[] b, int begin_index, int len)

Here you can find the source of toInt(byte[] b, int begin_index, int len)

Description

to Int

License

Open Source License

Declaration

public static int toInt(byte[] b, int begin_index, int len) 

Method Source Code

//package com.java2s;

public class Main {

    public static int toInt(byte[] b, int begin_index, int len) {
        byte[] a = subset(b, begin_index, len);
        int n = 0;
        if (a == null || a.length == 0)
            return n;
        for (int i = 0; i < a.length; i++) {
            n += ((a[i] & 0xff) << ((a.length - i - 1) * 8));
        }//w  w w .  ja va2  s  .  c  o  m
        return n;
    }

    public static byte[] subset(byte[] a, int begin_index, int len) {
        if (a == null)
            return null;
        if (begin_index < 0 || len <= 0 || begin_index >= a.length || len > a.length - begin_index)
            throw new IllegalArgumentException("Wrong arguments: array length:" + a.length + ", begin index:"
                    + begin_index + ", subset length:" + len);
        byte[] b = new byte[len];
        for (int i = 0; i < len; i++) {
            b[i] = a[i + begin_index];
        }
        return b;
    }
}

Related

  1. toInt(byte[] b)
  2. toInt(byte[] b)
  3. toInt(byte[] b)
  4. toInt(byte[] b)
  5. toInt(byte[] b)
  6. toInt(byte[] block, int pos, int len)
  7. toInt(byte[] bRefArr)
  8. toInt(byte[] buf)
  9. toInt(byte[] buf)