Java Utililty Methods Unsigned Number Create

List of utility methods to do Unsigned Number Create

Description

The list of methods to do Unsigned Number Create are organized into topic(s).

Method

longunsigned(int num)
unsigned
return 0xFFFFFFFFL & num;
longunsigned(int val)
Considers the bits of a signed 32-bit integer, and converts it into a long integer as if it were unsigned, i.e.
return val >= 0 ? val : ((val & 0x7FFFFFFF) | (1L << 31));
intunsigned(short value)
Convert a short into its unsigned representation as int.
return value & 0x0000ffff;
longunsigned16(short s)
unsigned
return s & 0xFFFFL;
byte[]unsigned32ToBytes(long value)
unsigned To Bytes
return toBytes(value, 4);
longunsigned32ToInt(byte[] bytes)
unsigned To Int
return fromBytes(bytes, 4);
longunsigned4BytesToInt(byte[] buf, int pos)
unsigned Bytes To Int
int firstByte = 0;
int secondByte = 0;
int thirdByte = 0;
int fourthByte = 0;
int index = pos;
firstByte = (0x000000FF & ((int) buf[index]));
secondByte = (0x000000FF & ((int) buf[index + 1]));
thirdByte = (0x000000FF & ((int) buf[index + 2]));
...
intunsigned8(byte b)
unsigned
return b & 0xFF;
intunsigned_byte(byte b)
unsignebyte
return b & 0xff;
booleanunsignedAddOverflow(int operand1, int operand2)
Returns true, if the addition of both operands as unsigned integers will cause an overflow.
long value1 = (long) operand1 & 0xFFFFFFFFL;
long value2 = (long) operand2 & 0xFFFFFFFFL;
return ((value1 + value2) & 0x100000000L) != 0;