Example usage for java.nio ByteOrder LITTLE_ENDIAN

List of usage examples for java.nio ByteOrder LITTLE_ENDIAN

Introduction

In this page you can find the example usage for java.nio ByteOrder LITTLE_ENDIAN.

Prototype

ByteOrder LITTLE_ENDIAN

To view the source code for java.nio ByteOrder LITTLE_ENDIAN.

Click Source Link

Document

This constant represents little endian.

Usage

From source file:Main.java

public static int my_bb_to_int_le(byte[] byteBarray) {
    return ByteBuffer.wrap(byteBarray).order(ByteOrder.LITTLE_ENDIAN).getInt();
}

From source file:Main.java

private static void checkByteOrderLittleEndian(final ByteBuffer buffer) {
    if (buffer.order() != ByteOrder.LITTLE_ENDIAN) {
        throw new IllegalArgumentException("ByteBuffer byte order must be little endian");
    }// w w w  .  ja  v a2s.co  m
}

From source file:Main.java

public static int toInt(byte[] bytes) {
    bb = ByteBuffer.wrap(bytes, 0, bytes.length);
    bb.order(ByteOrder.LITTLE_ENDIAN);
    return bb.getInt();
}

From source file:Main.java

public static byte[] shortToByteArray(int value) {
    ByteBuffer bb = ByteBuffer.allocate(2);
    bb.order(ByteOrder.LITTLE_ENDIAN);
    bb.putShort((short) value);
    return bb.array();
}

From source file:Main.java

public static float toFloat(byte[] bytes) {
    bb = ByteBuffer.wrap(bytes, 0, bytes.length);
    bb.order(ByteOrder.LITTLE_ENDIAN);
    return bb.getFloat();
}

From source file:Main.java

public static int toUnsignedShort(byte[] bytes) {
    bb = ByteBuffer.wrap(bytes, 0, bytes.length);
    bb.order(ByteOrder.LITTLE_ENDIAN);
    return bb.getShort() & 0xffff;
}

From source file:Main.java

public static short toUnsignedByte(byte bytes) {
    bb = ByteBuffer.allocate(1);/* w  ww . j a  va 2 s.  c  o  m*/
    bb.put(bytes);
    bb.order(ByteOrder.LITTLE_ENDIAN);
    return (short) (bb.get() & 0xff);
}

From source file:Main.java

private static short stream2Short(byte[] stream, int offset) {
    ByteBuffer buffer = ByteBuffer.allocate(2);
    buffer.order(ByteOrder.LITTLE_ENDIAN);
    buffer.put(stream[offset]);/*from   w  w w .java 2s .co  m*/
    buffer.put(stream[offset + 1]);
    return buffer.getShort(0);
}

From source file:Main.java

public static byte[] shortArr2byteArr(final short[] pcm, final int length) {
    byte[] dst = new byte[length * 2];
    ByteBuffer buf = ByteBuffer.wrap(dst);
    buf.order(ByteOrder.LITTLE_ENDIAN).asShortBuffer().put(pcm, 0, length);
    return dst;/*from w ww  . j  a  v a2  s  .c o  m*/
}

From source file:Main.java

public static byte[] intToByteArrayLE(int value) {
    ByteBuffer buffer = ByteBuffer.allocate(Integer.SIZE / Byte.SIZE);
    buffer.order(ByteOrder.LITTLE_ENDIAN);
    buffer.putInt(value);//from   w w  w  .  j ava  2s . com
    return buffer.array();
}