Java ByteBuffer Read readFourByteInt(ByteBuffer buffer, int start)

Here you can find the source of readFourByteInt(ByteBuffer buffer, int start)

Description

read Four Byte Int

License

Open Source License

Declaration

public static int readFourByteInt(ByteBuffer buffer, int start) 

Method Source Code


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

import java.nio.ByteBuffer;

public class Main {
    public static int readFourByteInt(ByteBuffer buffer, int start) {
        final byte b1 = buffer.get(start);
        final byte b2 = buffer.get(start + 1);
        final byte b3 = buffer.get(start + 2);
        final byte b4 = buffer.get(start + 3);
        return ((b1 & 255) << 24) | ((b2 & 255) << 16) | ((b3 & 255) << 8) | (b4 & 255);
    }/*  w w  w  . ja va 2 s .c  o  m*/

    public static int readFourByteInt(byte[] array, int start) {
        return ((array[start] & 255) << 24) | ((array[start + 1] & 255) << 16) | ((array[start + 2] & 255) << 8)
                | (array[start + 3] & 255);
    }
}

Related

  1. readDword(ByteBuffer buffer)
  2. readFileToByteBuffer(File file)
  3. readFixedLengthString(ByteBuffer buf, int length)
  4. readFixedLengthString(ByteBuffer byteBuffer, int size)
  5. readFixedPoint88(ByteBuffer bb)
  6. readFrom(File file, ByteBuffer buffer)
  7. readFully(final FileChannel src, final ByteBuffer dst, final long position)
  8. readHealthFloat16(ByteBuffer data)
  9. readHexString(ByteBuffer buffer, int nrBytes)