Here you can find the source of toShort(byte[] bytes, int offset)
Parameter | Description |
---|---|
bytes | a parameter |
offset | a parameter |
public static short toShort(byte[] bytes, int offset)
//package com.java2s; /*//from ww w . j a v a 2 s .c o m * This file is part of org.kalmeo.util. * * org.kalmeo.util 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 3 of the License, or * (at your option) any later version. * * org.kalmeo.util 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 org.kalmeo.util. If not, see <http://www.gnu.org/licenses/>. * * Creation date : 17 janv. 08 * Copyright (c) Kalmeo 2007-2008. All rights reserved. * http://www.kalmeo.org */ public class Main { /** * Convert a byte array to a short value * * @param bytes * @param offset * @return the short value corresponding to the 2 first bytes of the byte * array */ public static short toShort(byte[] bytes, int offset) { short value = 0; if (bytes != null && bytes.length >= 2) { value += (0x000000FF & bytes[offset]) << 8; value += (0x000000FF & bytes[offset + 1]); } return value; } }