Java Byte Array to Short bytesToShort(final byte byte0, final byte byte1)

Here you can find the source of bytesToShort(final byte byte0, final byte byte1)

Description

Read short value from two bytes.

License

Apache License

Parameter

Parameter Description
byte0 byte zero.
byte1 byte one.

Return

the read value

Declaration

public static short bytesToShort(final byte byte0, final byte byte1) 

Method Source Code

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

public class Main {
    /** 0 bits for shift. */
    private static final int BITS_0 = 0;
    /** 8 bits for shift. */
    private static final int BITS_8 = 8;
    /** Maximum value of byte. */
    private static final int BYTE_MAX = 0xFF;

    /**/*  w w w  .j av  a 2s  .  c  o  m*/
     * Read short value from two bytes.
     * 
     * @param byte0 byte zero.
     * @param byte1 byte one.
     * @return the read value
     */
    public static short bytesToShort(final byte byte0, final byte byte1) {
        return (short) ((byte0 << BITS_8) + ((byte1 & BYTE_MAX) << BITS_0));
    }
}

Related

  1. bytesToShort(byte[] bytes, int off, int len, boolean little)
  2. bytesToShort(byte[] bytes, int offset)
  3. bytesToShort(byte[] bytes, int start)
  4. bytesToShort(byte[] bytes, int startIndex)
  5. bytesToShort(byte[] shortBytes)
  6. bytesToShort(final byte[] aBuffer, final int aPos)
  7. bytesToShort(final byte[] data)
  8. bytesToShort16(byte highByte, byte lowByte)
  9. bytesToShortBE(byte[] bytes, int off)