Here you can find the source of toShort(final byte[] b)
Parameter | Description |
---|---|
b | The byte[] to convert. |
public static short toShort(final byte[] b)
//package com.java2s; /**//from w ww . j ava2s . c o m * Copyright 2003-2004 The Apache Software Foundation. Licensed under the Apache License, * Version 2.0 (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed * to in writing, software distributed under the License is distributed on an "AS IS" * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under the * License. * <p> * Static methods for managing byte arrays (all methods follow Big Endian order where most * significant bits are in front). * </p> * * @author Commons-Id Team * @version $Id: Bytes.java,v 1.1 2004/05/31 06:54:24 treilly Exp $ {@link http * ://jakarta.apache.org/turbine/turbine-2.3/} */ public class Main { /** * Build a short from first 2 bytes of the array. * * @param b * The byte[] to convert. * @return A short. */ public static short toShort(final byte[] b) { return (short) ((b[1] & 0xFF) + ((b[0] & 0xFF) << 8)); } }