Java Byte Array to Short bytesToShort(byte[] shortBytes)

Here you can find the source of bytesToShort(byte[] shortBytes)

Description

bytes To Short

License

Open Source License

Declaration

public static short bytesToShort(byte[] shortBytes) 

Method Source Code

//package com.java2s;
/*//from   www.j  av  a  2  s.  c om
 * @(#)ByteConvertUtil.java   V0.0.1 2015-2-3, ????1:37:07
 *
 * Copyright 2015 www.ifood517.com. All rights reserved.
 * www.ifood517.com PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

public class Main {

    public static short bytesToShort(byte[] shortBytes) {
        byte[] data = new byte[2];
        System.arraycopy(shortBytes, 0, data, 0, 2);
        return (short) (((data[0] << 8) | data[1] & 0xff));
    }

    public static short bytesToShort(byte[] shortBytes, int index) {
        byte[] data = new byte[2];
        System.arraycopy(shortBytes, index, data, 0, 2);
        return (short) (((data[0] << 8) | data[1] & 0xff));
    }
}

Related

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