Java ByteOrder getMostSignificantByte(byte[] bytes, ByteOrder byteOrder)

Here you can find the source of getMostSignificantByte(byte[] bytes, ByteOrder byteOrder)

Description

Return the most significant byte in the provided byte array based on endianess.

License

Apache License

Parameter

Parameter Description
bytes a parameter
byteOrder a parameter

Return

the most significant byte based on endianess.

Declaration

private static byte getMostSignificantByte(byte[] bytes, ByteOrder byteOrder) 

Method Source Code

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

import java.nio.ByteOrder;

public class Main {
    /**//  w  w  w.  ja v  a  2 s  .com
     * Return the most significant byte in the provided byte array based on endianess.
     * 
     * @param bytes
     * @param byteOrder
     * @return the most significant byte based on endianess.
     */
    private static byte getMostSignificantByte(byte[] bytes, ByteOrder byteOrder) {
        byte mostSignificantByte = bytes[0];
        if (byteOrder == ByteOrder.BIG_ENDIAN) {
            // do nothing
            // mostSignificantByte = bytes[0];
        } else if (byteOrder == ByteOrder.LITTLE_ENDIAN) {
            mostSignificantByte = bytes[bytes.length - 1];
        } else {
            throw new IllegalStateException("Unrecognized ByteOrder value[" + byteOrder + "].");
        }
        return mostSignificantByte;
    }
}

Related

  1. get24BitInt(byte b1, byte b2, byte b3, ByteOrder order)
  2. getByteOrder(final String value)
  3. getInt(byte[] b, int start, int end, ByteOrder byteOrder)
  4. getInt(final int offset, final byte[] buffer, final ByteOrder byteOrder)
  5. getLong(byte[] b, int start, int end, ByteOrder byteOrder)
  6. getUnsignedShort(final int offset, final byte[] buffer, final ByteOrder byteOrder)
  7. increaseNumberOfBytes(byte[] originalBytes, int desiredNumberOfBytes, ByteOrder byteOrder, boolean isSigned)
  8. isNegative(byte[] bytes, ByteOrder byteOrder, boolean isSigned)
  9. longToBytes(long longValue, ByteOrder byteOrder, boolean isSigned)