Here you can find the source of bytesToShort(byte[] bytes)
Parameter | Description |
---|---|
bytes | the bytes which to convert |
public static short bytesToShort(byte[] bytes)
//package com.java2s; //License from project: Open Source License public class Main { /**// ww w . j a v a2 s .c om * Convert a byte array into a short takes the 4 smallest bits of every byte, you can give an * array with less or more than 4 bytes put you have a risk of overflow or an unexpected result * @param bytes the bytes which to convert * * @return the short created */ public static short bytesToShort(byte[] bytes) { short num = 0; for (int i = 0; i < bytes.length; i++) { num += (bytes[i] & 0xF) << (i * 4); } return num; } }