Android Byte to Short Convert getShort(byte b1, byte b2)

Here you can find the source of getShort(byte b1, byte b2)

Description

Gets an short from two bytes

License

Open Source License

Parameter

Parameter Description
b2 the second byte
b1 the first byte

Return

The short value

Declaration

public static short getShort(byte b1, byte b2) 

Method Source Code

//package com.java2s;
/*********************************************************************
 *
 *      Copyright (C) 2002 Andrew Khan//  ww  w . j av  a2s.  c o m
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 ***************************************************************************/

public class Main {
    /**
     * Gets an short from two bytes
     *
     * @param b2 the second byte
     * @param b1 the first byte
     * @return The short value
     */
    public static short getShort(byte b1, byte b2) {
        short i1 = (short) (b1 & 0xff);
        short i2 = (short) (b2 & 0xff);
        short val = (short) (i2 << 8 | i1);
        return val;
    }
}