Here you can find the source of bytesToShort(byte[] bytes, int startIndex)
Parameter | Description |
---|---|
bytes | the byte array |
startIndex | the starting index of the place the int is stored |
public static short bytesToShort(byte[] bytes, int startIndex)
//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)); } }