Here you can find the source of bytesToShort(final byte byte0, final byte byte1)
Parameter | Description |
---|---|
byte0 | byte zero. |
byte1 | byte one. |
public static short bytesToShort(final byte byte0, final byte byte1)
//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)); } }