Java Byte Array to Short bytesToShort(byte[] bytes, int startIndex)

Here you can find the source of bytesToShort(byte[] bytes, int startIndex)

Description

Given a byte array, restore it as a short

License

Open Source License

Parameter

Parameter Description
bytes the byte array
startIndex the starting index of the place the int is stored

Declaration

public static short bytesToShort(byte[] bytes, int startIndex) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*w ww  .  j ava  2  s  .  c  om*/
     * Given a byte array, restore it as a short
     * 
     * @param bytes
     *            the byte array
     * @param startIndex
     *            the starting index of the place the int is stored
     */
    public static short bytesToShort(byte[] bytes, int startIndex) {
        return (short) (((int) bytes[startIndex] & 0xff) | (((int) bytes[startIndex + 1] & 0xff) << 8));
    }
}

Related

  1. bytesToShort(byte[] bytes, int off)
  2. bytesToShort(byte[] bytes, int off, boolean bigEndian)
  3. bytesToShort(byte[] bytes, int off, int len, boolean little)
  4. bytesToShort(byte[] bytes, int offset)
  5. bytesToShort(byte[] bytes, int start)
  6. bytesToShort(byte[] shortBytes)
  7. bytesToShort(final byte byte0, final byte byte1)
  8. bytesToShort(final byte[] aBuffer, final int aPos)
  9. bytesToShort(final byte[] data)