Java Byte Array to Short bytesToShort(byte hiByte, byte loByte)

Here you can find the source of bytesToShort(byte hiByte, byte loByte)

Description

Reconstructs a short from its hi and low bytes.

License

Open Source License

Parameter

Parameter Description
hiByte the high byte
loByte the low byte

Return

the short value

Declaration

public static final short bytesToShort(byte hiByte, byte loByte) 

Method Source Code

//package com.java2s;
/**//from  w w w.  j  a va  2 s.  co m
 * Portions Copyright 2001 Sun Microsystems, Inc.
 * Portions Copyright 1999-2001 Language Technologies Institute, 
 * Carnegie Mellon University.
 * All Rights Reserved.  Use is subject to license terms.
 * 
 * See the file "license.terms" for information on usage and
 * redistribution of this file, and for a DISCLAIMER OF ALL 
 * WARRANTIES.
 */

public class Main {
    /** Reconstructs a short from its hi and low bytes.
     * @param hiByte the high byte
     * @param loByte the low byte
     * @return the short value */
    public static final short bytesToShort(byte hiByte, byte loByte) {
        int result = (0x000000FF & hiByte);
        result = result << 8;
        result |= (0x000000FF & loByte);
        return (short) result;
    }
}

Related

  1. bytes2short(byte[] src)
  2. bytesToShort(byte A, byte B)
  3. bytesToShort(byte a, byte b, boolean swapBytes)
  4. bytesToShort(byte b1, byte b2)
  5. bytesToShort(byte byte1, byte byte2)
  6. bytesToShort(byte[] buf)
  7. bytesToShort(byte[] buffer, int index)
  8. bytesToShort(byte[] bytes)
  9. bytesToShort(byte[] bytes)