Java Integer From intFromBytes(byte[] bytes)

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

Description

int From Bytes

License

Open Source License

Declaration

public static int intFromBytes(byte[] bytes) 

Method Source Code

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

public class Main {
    public static int intFromBytes(byte[] bytes) {
        int x1 = bytes[0];
        int x2 = bytes[1];
        int x3 = bytes[2];
        int x4 = bytes[3];

        if (x1 < 0)
            x1 = x1 + 256;/*from w ww  .  j a  va  2  s . c  o m*/
        if (x2 < 0)
            x2 = x2 + 256;
        if (x3 < 0)
            x3 = x3 + 256;
        if (x4 < 0)
            x4 = x4 + 256;

        return ((x1 << 24) + (x2 << 16) + (x3 << 8) + x4);
    }
}

Related

  1. intFromByteRGB(byte[] reds, byte[] greens, byte[] blues)
  2. intFromBytes(byte[] b)
  3. intFrombytes(byte[] b, int pos)
  4. intFromBytes(byte[] buffer)
  5. intFromBytes(byte[] buffer, int offset)
  6. intFromBytes(byte[] bytes)
  7. intFromBytes(byte[] bytes, int offset)
  8. intFromByteWithoutStupidJavaSignExtension(byte val)
  9. intFromHex(String hex, boolean signed)