Java Byte Array to Int bytes2Integer(byte[] byteVal)

Here you can find the source of bytes2Integer(byte[] byteVal)

Description

bytes Integer

License

Apache License

Declaration

public static int bytes2Integer(byte[] byteVal) 

Method Source Code

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

public class Main {
    public static int bytes2Integer(byte[] byteVal) {
        int result = 0;
        for (int i = 0; i < byteVal.length; i++) {
            int tmpVal = (byteVal[i] << (8 * (3 - i)));
            switch (i) {
            case 0:
                tmpVal = tmpVal & 0xFF000000;
                break;
            case 1:
                tmpVal = tmpVal & 0x00FF0000;
                break;
            case 2:
                tmpVal = tmpVal & 0x0000FF00;
                break;
            case 3:
                tmpVal = tmpVal & 0x000000FF;
                break;
            }//from   ww w  .  j av a  2 s . c o m
            result = result | tmpVal;
        }
        return result;
    }
}

Related

  1. bytes2Int(byte[] src, int start)
  2. Bytes2Int16(byte[] sour, int offset)
  3. Bytes2Int32(byte[] sour, int offset)
  4. Bytes2Int64(byte[] sour, int offset)
  5. bytes2IntArray(byte[] bytes)
  6. bytes2LengthToIntLowOrder(byte[] intBytes)
  7. bytes2ToInt(byte[] inputValues)
  8. Bytes2Uint32(byte[] sour, int offset)
  9. bytesToInt(byte a)