Here you can find the source of getUnsignedSafe(byte[] buffer, int pos)
Parameter | Description |
---|---|
buffer | a parameter |
pos | : index of the byte in the buffer. |
public static int getUnsignedSafe(byte[] buffer, int pos)
//package com.java2s; public class Main { /**/*from www . ja v a 2 s .co m*/ * Convert byte from byte buffer to unsigned integer. * @param buffer * @param pos : index of the byte in the buffer. * @return */ public static int getUnsignedSafe(byte[] buffer, int pos) { if (null == buffer || pos >= buffer.length || pos < 0) { return 0; } int res = toUnsignedInteger(buffer[pos]); return res; } /** * Convert byte to unsigned integer. * @param b * @return */ public static int toUnsignedInteger(byte b) { int n = b >= 0 ? b : b + 256; return n; } }