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

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

Description

bytes To Int

License

Apache License

Declaration

public static int bytesToInt(byte[] b) 

Method Source Code

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

public class Main {
    public static int bytesToInt(byte[] b) {
        int i = (b[0] << 24) & 0xFF000000;
        i |= (b[1] << 16) & 0xFF0000;
        i |= (b[2] << 8) & 0xFF00;
        i |= b[3] & 0xFF;/*from  w w w .j a  va 2 s.com*/
        return i;
    }

    public static int bytesToInt(byte[] bytes, int start) {
        int num = bytes[start] & 0xFF;
        num |= ((bytes[start + 1] << 8) & 0xFF00);
        num |= ((bytes[start + 2] << 16) & 0xFF0000);
        num |= ((bytes[start + 3] << 24) & 0xFF000000);
        return num;
    }
}

Related

  1. bytesToInt(byte bytes[], int start)
  2. bytesToInt(byte low, byte high)
  3. bytesToInt(byte[] array, int offset)
  4. bytesToInt(byte[] array, int offset)
  5. bytesToInt(byte[] b)
  6. bytesToInt(byte[] b)
  7. bytesToInt(byte[] b)
  8. bytesToInt(byte[] b)
  9. bytesToInt(byte[] b, int i)