Java Short Number Create toShort(final byte[] b)

Here you can find the source of toShort(final byte[] b)

Description

Build a short from first 2 bytes of the array.

License

Apache License

Parameter

Parameter Description
b The byte[] to convert.

Return

A short.

Declaration

public static short toShort(final byte[] b) 

Method Source Code

//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));
    }
}

Related

  1. toShort(byte[] readBuffer, int o)
  2. toShort(byte[] si, boolean isReverseOrder)
  3. toShort(byte[] src)
  4. toShort(byte[] value)
  5. toShort(char[] bytes, boolean le)
  6. toShort(final byte[] b)
  7. toShort(final byte[] buffer, final int offset, final int length)
  8. toShort(final byte[] inputBytes, int offset)
  9. toShort(final String bitString)