Class SignednessUtil
java.lang.Object
org.checkerframework.checker.signedness.util.SignednessUtil
Provides static utility methods for unsigned values, beyond what is available in the JDK's
Unsigned Integer API. The JDK's Unsigned Integer API is methods in primitive wrapper classes and
in classes
Arrays, RandomAccessFile, ObjectInputStream, and
DataInputStream.
SignednessUtilExtra has more methods that reference packages that Android does not
provide. That is, SignednessUtil can be used anywhere, and SignednessUtilExtra
can be used anywhere except on Android.
- See the Checker Framework Manual:
- Utility routines for manipulating unsigned values
-
Method Summary
Modifier and TypeMethodDescriptionstatic @Unsigned bytebyteFromDouble(double d) Returns an unsigned byte representing the same value as the double.static @Unsigned bytebyteFromFloat(float f) Returns an unsigned byte representing the same value as the float.static intcompareUnsigned(@Unsigned byte x, @Unsigned byte y) Compares two unsigned bytes x and y.static intcompareUnsigned(@Unsigned short x, @Unsigned short y) Compares two unsigned shorts x and y.static @Unsigned byteGets an unsigned byte from the ByteBuffer b.static voidgetUnsigned(ByteBuffer b, @Unsigned byte[] bs) Gets an array of unsigned bytes from the ByteBuffer b and stores them in the array bs.static ByteBuffergetUnsigned(ByteBuffer b, byte[] bs, int i, int l) Populates an unsigned byte array from the ByteBuffer b at i with l bytes.static @Unsigned bytegetUnsigned(ByteBuffer b, int i) Gets an unsigned byte from the ByteBuffer b at i.static @Unsigned intgetUnsigned(IntBuffer b, int i) Gets an unsigned int from the IntBuffer b at i.static @Unsigned intGets an unsigned int from the ByteBuffer b.static @Unsigned shortGets an unsigned short from the ByteBuffer b.static @Unsigned intintFromDouble(double d) Returns an unsigned int representing the same value as the double.static @Unsigned intintFromFloat(float f) Returns an unsigned int representing the same value as the float.static @Unsigned longlongFromDouble(double d) Returns an unsigned long representing the same value as the double.static @Unsigned longlongFromFloat(float f) Returns an unsigned long representing the same value as the float.static ByteBufferputUnsigned(ByteBuffer b, @Unsigned byte ubyte) Places an unsigned byte into the ByteBuffer b.static ByteBufferputUnsigned(ByteBuffer b, int i, @Unsigned byte ubyte) Places an unsigned byte into the ByteBuffer b at i.static IntBufferputUnsigned(IntBuffer b, @Unsigned int uint) Places an unsigned int into the IntBuffer b.static IntBufferputUnsigned(IntBuffer b, @Unsigned int[] uints) Places an unsigned int array into the IntBuffer b.static IntBufferputUnsigned(IntBuffer b, @Unsigned int[] uints, int i, int l) Places an unsigned int array into the IntBuffer b at i with length l.static IntBufferputUnsigned(IntBuffer b, int i, @Unsigned int uint) Places an unsigned int into the IntBuffer b at i.static ByteBufferputUnsignedInt(ByteBuffer b, @Unsigned int uint) Places an unsigned int into the ByteBuffer b.static ByteBufferputUnsignedInt(ByteBuffer b, int i, @Unsigned int uint) Places an unsigned int into the ByteBuffer b at i.static ByteBufferputUnsignedLong(ByteBuffer b, int i, @Unsigned long ulong) Places an unsigned long into the ByteBuffer b at i.static ByteBufferputUnsignedShort(ByteBuffer b, @Unsigned short ushort) Places an unsigned short into the ByteBuffer b.static ByteBufferputUnsignedShort(ByteBuffer b, int i, @Unsigned short ushort) Places an unsigned short into the ByteBuffer b at i.static voidreadFullyUnsigned(RandomAccessFile f, @Unsigned byte[] b) Reads a file fully into an unsigned byte array.static intreadUnsigned(RandomAccessFile f, @Unsigned byte[] b, int off, int len) Reads up tolenbytes of data from this file into an unsigned array of bytes.static @Unsigned charReads an unsigned char from the RandomAccessFile f.static @Unsigned intReads an unsigned int from the RandomAccessFile f.static @Unsigned longReads an unsigned long from the RandomAccessFile f.static @Unsigned shortshortFromDouble(double d) Returns an unsigned short representing the same value as the double.static @Unsigned shortshortFromFloat(float f) Returns an unsigned short representing the same value as the float.static doubleReturns a double representing the same value as the unsigned byte.static doubleReturns a double representing the same value as the unsigned int.static doubleReturns a double representing the same value as the unsigned long.static doubleReturns a double representing the same value as the unsigned short.static floatReturns a float representing the same value as the unsigned byte.static floatReturns a float representing the same value as the unsigned int.static floatReturns a float representing the same value as the unsigned long.static floatReturns a float representing the same value as the unsigned short.static @Unsigned inttoUnsignedInt(@Unsigned char c) Returns an unsigned int representing the same value as an unsigned char.static @Unsigned longtoUnsignedLong(@Unsigned char c) Returns an unsigned long representing the same value as an unsigned char.static @Unsigned shorttoUnsignedShort(@Unsigned byte b) Returns an unsigned short representing the same value as an unsigned byte.static @Unsigned shorttoUnsignedShort(@Unsigned char c) Returns an unsigned short representing the same value as an unsigned char.static StringtoUnsignedString(@Unsigned byte b) Produces a string representation of the unsigned byte b.static StringtoUnsignedString(@Unsigned byte b, int radix) Produces a string representation of the unsigned byte b in base radix.static StringtoUnsignedString(@Unsigned short s) Produces a string representation of the unsigned short s.static StringtoUnsignedString(@Unsigned short s, int radix) Produces a string representation of the unsigned short s in base radix.static ByteBufferwrapUnsigned(@Unsigned byte[] array) Wraps an unsigned byte array into a ByteBuffer.static ByteBufferwrapUnsigned(@Unsigned byte[] array, int offset, int length) Wraps an unsigned byte array into a ByteBuffer.static voidwriteUnsigned(RandomAccessFile f, @Unsigned byte[] bs, int off, int len) Writes len unsigned bytes to the RandomAccessFile f at offset off.static voidwriteUnsignedByte(RandomAccessFile f, @Unsigned byte b) Writes an unsigned byte to the RandomAccessFile f.static voidwriteUnsignedChar(RandomAccessFile f, @Unsigned char c) Writes an unsigned char to the RandomAccessFile f.static voidwriteUnsignedInt(RandomAccessFile f, @Unsigned int i) Writes an unsigned byte to the RandomAccessFile f.static voidwriteUnsignedLong(RandomAccessFile f, @Unsigned long l) Writes an unsigned byte to the RandomAccessFile f.static voidwriteUnsignedShort(RandomAccessFile f, @Unsigned short s) Writes an unsigned short to the RandomAccessFile f.
-
Method Details
-
wrapUnsigned
Wraps an unsigned byte array into a ByteBuffer. This method is a wrapper aroundwrap(byte[]), but assumes that the input should be interpreted as unsigned. -
wrapUnsigned
Wraps an unsigned byte array into a ByteBuffer. This method is a wrapper aroundwrap(byte[], int, int), but assumes that the input should be interpreted as unsigned. -
getUnsignedInt
Gets an unsigned int from the ByteBuffer b. This method is a wrapper aroundgetInt(), but assumes that the result should be interpreted as unsigned. -
getUnsignedShort
Gets an unsigned short from the ByteBuffer b. This method is a wrapper aroundgetShort(), but assumes that the result should be interpreted as unsigned. -
getUnsigned
Gets an unsigned byte from the ByteBuffer b. This method is a wrapper aroundget(), but assumes that the result should be interpreted as unsigned. -
getUnsigned
Gets an unsigned byte from the ByteBuffer b at i. This method is a wrapper aroundget(int), but assumes that the result should be interpreted as unsigned. -
getUnsigned
Populates an unsigned byte array from the ByteBuffer b at i with l bytes. This method is a wrapper aroundget(byte[], int, int), but assumes that the bytes should be interpreted as unsigned. -
putUnsigned
Places an unsigned byte into the ByteBuffer b. This method is a wrapper aroundput(byte), but assumes that the input should be interpreted as unsigned. -
putUnsigned
Places an unsigned byte into the ByteBuffer b at i. This method is a wrapper aroundput(int, byte), but assumes that the input should be interpreted as unsigned. -
putUnsigned
-
putUnsigned
Places an unsigned int into the IntBuffer b at i. This method is a wrapper aroundput(int, int), but assumes that the input should be interpreted as unsigned. -
putUnsigned
Places an unsigned int array into the IntBuffer b. This method is a wrapper aroundput(int[]), but assumes that the input should be interpreted as unsigned. -
putUnsigned
Places an unsigned int array into the IntBuffer b at i with length l. This method is a wrapper aroundput(int[], int, int), but assumes that the input should be interpreted as unsigned. -
getUnsigned
-
putUnsignedShort
Places an unsigned short into the ByteBuffer b. This method is a wrapper aroundputShort(short), but assumes that the input should be interpreted as unsigned. -
putUnsignedShort
Places an unsigned short into the ByteBuffer b at i. This method is a wrapper aroundputShort(int, short), but assumes that the input should be interpreted as unsigned. -
putUnsignedInt
Places an unsigned int into the ByteBuffer b. This method is a wrapper aroundputInt(int), but assumes that the input should be interpreted as unsigned. -
putUnsignedInt
Places an unsigned int into the ByteBuffer b at i. This method is a wrapper aroundputInt(int, int), but assumes that the input should be interpreted as unsigned. -
putUnsignedLong
Places an unsigned long into the ByteBuffer b at i. This method is a wrapper aroundputLong(int, long), but assumes that the input should be interpreted as unsigned. -
readUnsignedChar
Reads an unsigned char from the RandomAccessFile f. This method is a wrapper aroundreadChar(), but assumes the output should be interpreted as unsigned.- Throws:
IOException
-
readUnsignedInt
Reads an unsigned int from the RandomAccessFile f. This method is a wrapper aroundreadInt(), but assumes the output should be interpreted as unsigned.- Throws:
IOException
-
readUnsignedLong
Reads an unsigned long from the RandomAccessFile f. This method is a wrapper aroundreadLong(), but assumes the output should be interpreted as unsigned.- Throws:
IOException
-
readUnsigned
public static int readUnsigned(RandomAccessFile f, @Unsigned byte[] b, int off, int len) throws IOException Reads up tolenbytes of data from this file into an unsigned array of bytes. This method is a wrapper aroundread(byte[], int, int), but assumes the output should be interpreted as unsigned.- Throws:
IOException
-
readFullyUnsigned
Reads a file fully into an unsigned byte array. This method is a wrapper aroundreadFully(byte[]), but assumes the output should be interpreted as unsigned.- Throws:
IOException
-
writeUnsigned
public static void writeUnsigned(RandomAccessFile f, @Unsigned byte[] bs, int off, int len) throws IOException Writes len unsigned bytes to the RandomAccessFile f at offset off. This method is a wrapper aroundwrite(byte[], int, int), but assumes the input should be interpreted as unsigned.- Throws:
IOException
-
writeUnsignedByte
Writes an unsigned byte to the RandomAccessFile f. This method is a wrapper aroundwriteByte(int), but assumes the input should be interpreted as unsigned.- Throws:
IOException
-
writeUnsignedChar
Writes an unsigned char to the RandomAccessFile f. This method is a wrapper aroundwriteChar(int), but assumes the input should be interpreted as unsigned.- Throws:
IOException
-
writeUnsignedShort
Writes an unsigned short to the RandomAccessFile f. This method is a wrapper aroundwriteShort(int), but assumes the input should be interpreted as unsigned.- Throws:
IOException
-
writeUnsignedInt
Writes an unsigned byte to the RandomAccessFile f. This method is a wrapper aroundwriteInt(int), but assumes the input should be interpreted as unsigned.- Throws:
IOException
-
writeUnsignedLong
Writes an unsigned byte to the RandomAccessFile f. This method is a wrapper aroundwriteLong(long), but assumes the input should be interpreted as unsigned.- Throws:
IOException
-
getUnsigned
Gets an array of unsigned bytes from the ByteBuffer b and stores them in the array bs. This method is a wrapper aroundget(byte[]), but assumes that the array of bytes should be interpreted as unsigned. -
compareUnsigned
Compares two unsigned shorts x and y.In Java 11 or later, use Short.compareUnsigned.
- Parameters:
x- the first value to comparey- the second value to compare- Returns:
- a negative number iff x < y, a positive number iff x > y, and zero iff x == y.
-
compareUnsigned
Compares two unsigned bytes x and y.In Java 11 or later, use Byte.compareUnsigned.
- Parameters:
x- the first value to comparey- the second value to compare- Returns:
- a negative number iff x < y, a positive number iff x > y, and zero iff x == y.
-
toUnsignedString
-
toUnsignedString
-
toUnsignedString
-
toUnsignedString
-
toUnsignedShort
-
toUnsignedLong
-
toUnsignedInt
-
toUnsignedShort
-
toFloat
Returns a float representing the same value as the unsigned byte. -
toFloat
Returns a float representing the same value as the unsigned short. -
toFloat
Returns a float representing the same value as the unsigned int. -
toFloat
Returns a float representing the same value as the unsigned long. -
toDouble
Returns a double representing the same value as the unsigned byte. -
toDouble
Returns a double representing the same value as the unsigned short. -
toDouble
Returns a double representing the same value as the unsigned int. -
toDouble
Returns a double representing the same value as the unsigned long. -
byteFromFloat
Returns an unsigned byte representing the same value as the float. -
shortFromFloat
Returns an unsigned short representing the same value as the float. -
intFromFloat
Returns an unsigned int representing the same value as the float. -
longFromFloat
Returns an unsigned long representing the same value as the float. -
byteFromDouble
Returns an unsigned byte representing the same value as the double. -
shortFromDouble
Returns an unsigned short representing the same value as the double. -
intFromDouble
Returns an unsigned int representing the same value as the double. -
longFromDouble
Returns an unsigned long representing the same value as the double.
-