Here you can find the source of toShort(byte msb, byte lsb)
Parameter | Description |
---|---|
msb | The Most Significant Byte. |
lsb | The Least Significant Byte. |
public static short toShort(byte msb, byte lsb)
//package com.java2s; /*//from w ww .j a v a2 s . co m * Copyright (C) 2014 Jesse Caulfield * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ public class Main { /** * Convert 2 bytes into a short. * <p> * This converts the 2 bytes into a short. The msb will be the high byte (8 * bits) of the short, and the lsb will be the low byte (8 bits) of the short. * * @param msb The Most Significant Byte. * @param lsb The Least Significant Byte. * @return A short representing the bytes. */ public static short toShort(byte msb, byte lsb) { return (short) ((0xff00 & (short) (msb << 8)) | (0x00ff & (short) lsb)); } public static short toShort(byte[] data) { if ((data == null) || (data.length != 2)) { return 0x0; } return (short) ((0xff & data[0]) << 8 | (0xff & data[1])); } }