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

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

Description

bytes To Int

License

Apache License

Declaration

public static int bytesToInt(byte[] b, int offset) 

Method Source Code

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

public class Main {
    public static int bytesToInt(byte[] b, int offset) {
        int value = 0;
        for (int i = 0; i < 4; i++) {
            int shift = (4 - 1 - i) * 8;
            value += (b[i + offset] & 0x000000FF) << shift;
        }//from   www  . ja v a 2  s.  c om
        return value;
    }

    public static int bytesToInt(byte[] bytes) {
        return (0xff & bytes[0]) | (0xff00 & (bytes[1] << 8)) | (0xff0000 & (bytes[2] << 16))
                | (0xff000000 & (bytes[3] << 24));
    }
}

Related

  1. bytesToInt(byte[] b)
  2. bytesToInt(byte[] b)
  3. bytesToInt(byte[] b)
  4. bytesToInt(byte[] b)
  5. bytesToInt(byte[] b, int i)
  6. bytesToInt(byte[] b, int offset)
  7. bytesToInt(byte[] buf, int offset)
  8. bytesToInt(byte[] buf, int startIdx)
  9. bytesToInt(byte[] buff, int off, int len)