Java Byte Array to Int bytes2Int(byte[] bytes, int defaultValue)

Here you can find the source of bytes2Int(byte[] bytes, int defaultValue)

Description

bytes Int

License

Open Source License

Declaration

public static int bytes2Int(byte[] bytes, int defaultValue) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static int bytes2Int(byte[] bytes, int defaultValue) {
        if (bytes == null) {
            return defaultValue;
        } else {//  w w  w  .  j  a  v a 2  s.c o m
            return bytes2Int(bytes);
        }
    }

    /**
     * convert bytes to integer. high byte store at left.
     * @param bytes
     * @return
     */
    public static int bytes2Int(byte[] bytes) {
        int num = 0;
        for (int ix = 0; ix < bytes.length; ++ix) {
            num <<= 8;
            num |= (bytes[ix] & 0xff);
        }
        return num;
    }
}

Related

  1. bytes2Int(byte[] bytes)
  2. bytes2int(byte[] bytes)
  3. bytes2int(byte[] bytes)
  4. bytes2int(byte[] bytes)
  5. bytes2int(byte[] bytes, int begin)
  6. bytes2Int(byte[] bytes, int offset)
  7. bytes2int(byte[] bytes, int offset, boolean bigEndian)
  8. bytes2int(byte[] in, int index1, int index2, int index3)
  9. bytes2int(byte[] src)