List of utility methods to do Unsigned Number Create
int | unsignedShortBytesToInt(byte[] b) Converts an array of 2 bytes representing an unsigned short to an int containing the short value. int i = b[1] & 0xFF; i <<= 8; i |= b[0] & 0xFF; return i; |
int | unsignedShortToInt(byte[] b) unsigned Short To Int int i = 0; i |= b[0] & 0xFF; i <<= 8; i |= b[1] & 0xFF; return i; |
int | unsignedShortToInt(final byte[] b) Converts a two byte array to an integer int i = 0; i |= b[0] & 0xFF; i <<= 8; i |= b[1] & 0xFF; return i; |
int | unsignedShortToInt(short n) Generate an integer from an unsigned short. return n & 0x0000FFFF;
|
boolean | unsignedSubOverflow(int operand1, int operand2) Returns true, if the subtraction of both operand1 - operand2 (both unsigned) will issue a borrow. operand1 += Integer.MIN_VALUE;
operand2 += Integer.MIN_VALUE;
return operand1 < operand2;
|
int | unsignedToBytes(byte b) unsigned To Bytes return b & 0xFF;
|
int | unsignedToSigned(int unsigned, int size) unsigned To Signed if ((unsigned & (1 << size - 1)) != 0) unsigned = -1 * ((1 << size - 1) - (unsigned & ((1 << size - 1) - 1))); return unsigned; |
byte[] | unsignedToSigned(int[] ints) Convert an unsigned set of bytes to a signed set. final byte[] result = new byte[ints.length]; for (int i = 0; i < ints.length; i++) { result[i] = (byte) (ints[i] & 0xFF); return result; |
byte[] | unsignedToSigned(int[] unsignedBytes) unsigned To Signed byte[] signedBytes = new byte[unsignedBytes.length]; for (int i = 0; i < unsignedBytes.length; i++) { if (i < 0 || i > 255) { throw new IllegalArgumentException(String.format( "Invalid value at position %d: %d is not an unsigned 8-bit integer (between 0 and 255)", i, unsignedBytes[i])); signedBytes[i] = (byte) (unsignedBytes[i]); ... |
long | unsignedToSigned(long value, int size) unsigned To Signed long signbit = value & (1L << (size - 1)); return (signbit == 0) ? value : (value - (1L << size)); |