Here you can find the source of getByteLittleEndian_unit16(byte[] theBytes, int idx)
Parameter | Description |
---|---|
theBytes | - the array |
idx | - the starting index |
public static int getByteLittleEndian_unit16(byte[] theBytes, int idx)
//package com.java2s; public class Main { /**//from www. java 2 s . c om * pull out unsigned 16 bits integer out of the array. * @param theBytes - the array * @param idx - the starting index * @return the num (0-65535) */ public static int getByteLittleEndian_unit16(byte[] theBytes, int idx) { int sum = 0; for (int i = 0; i < 2; i++) { sum = (sum << 8) + (0xff & theBytes[i + idx]); } return flip16(sum); } /** * for switching big/small endian * @param num * @return filpped representation. */ public static int flip16(int num) { int tmp = num; tmp = ((tmp & 0x00FF) << 8) + ((tmp & 0xFF00) >> 8); return tmp; } }