Java Convert via ByteBuffer toInt(final byte lowOrderByte, final byte highOrderByte)

Here you can find the source of toInt(final byte lowOrderByte, final byte highOrderByte)

Description

to Int

License

Open Source License

Declaration

public static int toInt(final byte lowOrderByte,
            final byte highOrderByte) 

Method Source Code

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

import java.nio.ByteBuffer;
import java.nio.ByteOrder;

public class Main {
    public static int toInt(final byte lowOrderByte,
            final byte highOrderByte) {
        return toInt(lowOrderByte, highOrderByte, ByteOrder.LITTLE_ENDIAN);
    }/*from w  w  w .j  a v a  2s .co m*/

    public static int toInt(final byte lowOrderByte,
            final byte highOrderByte, final ByteOrder byteOrder) {
        ByteBuffer byteBuffer = ByteBuffer.allocateDirect(4);
        byteBuffer.order(byteOrder);
        byteBuffer.put(lowOrderByte);
        byteBuffer.put(highOrderByte);
        byteBuffer.put((byte) 0x00);
        byteBuffer.put((byte) 0x00);
        byteBuffer.flip();
        return byteBuffer.getInt();
    }
}

Related

  1. toHexBytes(byte[] bytes)
  2. toHexString(Number n)
  3. toInt(byte[] bytes)
  4. toInt(byte[] data)
  5. toInt(byte[] value)
  6. toInt(InetAddress address)
  7. toIntArray(byte[] byteArray)
  8. toIntArray(byte[] byteArray)
  9. toIntArray(final byte[] byteArray)