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

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

Description

bytes To Int

License

Apache License

Declaration

public static int bytesToInt(byte[] bytes) 

Method Source Code

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

public class Main {
    public static int bytesToInt(byte[] bytes) {
        return (0xff & bytes[0]) | (0xff00 & (bytes[1] << 8)) | (0xff0000 & (bytes[2] << 16))
                | (0xff000000 & (bytes[3] << 24));
    }//from  ww  w. jav  a  2  s  .c om

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

Related

  1. bytesToInt(byte[] bytes)
  2. bytesToInt(byte[] bytes)
  3. bytesToInt(byte[] bytes)
  4. bytesToInt(byte[] bytes)
  5. bytesToInt(byte[] bytes)
  6. bytesToInt(byte[] bytes)
  7. bytesToInt(byte[] bytes, int bitOffset, int bitCount)
  8. bytesToInt(byte[] bytes, int offset)
  9. bytesToInt(byte[] bytes, int offset, int length)