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 SummaryModifier and TypeMethodDescriptionstatic @org.checkerframework.checker.signedness.qual.Unsigned bytebyteFromDouble(double d) Returns an unsigned byte representing the same value as the double.static @org.checkerframework.checker.signedness.qual.Unsigned bytebyteFromFloat(float f) Returns an unsigned byte representing the same value as the float.static intcompareUnsigned(@org.checkerframework.checker.signedness.qual.Unsigned byte x, @org.checkerframework.checker.signedness.qual.Unsigned byte y) Compares two unsigned bytes x and y.static intcompareUnsigned(@org.checkerframework.checker.signedness.qual.Unsigned short x, @org.checkerframework.checker.signedness.qual.Unsigned short y) Compares two unsigned shorts x and y.static @org.checkerframework.checker.signedness.qual.Unsigned byteGets an unsigned byte from the ByteBuffer b.static voidgetUnsigned(ByteBuffer b, @org.checkerframework.checker.signedness.qual.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 @org.checkerframework.checker.signedness.qual.Unsigned bytegetUnsigned(ByteBuffer b, int i) Gets an unsigned byte from the ByteBuffer b at i.static @org.checkerframework.checker.signedness.qual.Unsigned intgetUnsigned(IntBuffer b, int i) Gets an unsigned int from the IntBuffer b at i.static @org.checkerframework.checker.signedness.qual.Unsigned intGets an unsigned int from the ByteBuffer b.static @org.checkerframework.checker.signedness.qual.Unsigned shortGets an unsigned short from the ByteBuffer b.static @org.checkerframework.checker.signedness.qual.Unsigned intintFromDouble(double d) Returns an unsigned int representing the same value as the double.static @org.checkerframework.checker.signedness.qual.Unsigned intintFromFloat(float f) Returns an unsigned int representing the same value as the float.static @org.checkerframework.checker.signedness.qual.Unsigned longlongFromDouble(double d) Returns an unsigned long representing the same value as the double.static @org.checkerframework.checker.signedness.qual.Unsigned longlongFromFloat(float f) Returns an unsigned long representing the same value as the float.static ByteBufferputUnsigned(ByteBuffer b, @org.checkerframework.checker.signedness.qual.Unsigned byte ubyte) Places an unsigned byte into the ByteBuffer b.static ByteBufferputUnsigned(ByteBuffer b, int i, @org.checkerframework.checker.signedness.qual.Unsigned byte ubyte) Places an unsigned byte into the ByteBuffer b at i.static IntBufferputUnsigned(IntBuffer b, @org.checkerframework.checker.signedness.qual.Unsigned int uint) Places an unsigned int into the IntBuffer b.static IntBufferputUnsigned(IntBuffer b, @org.checkerframework.checker.signedness.qual.Unsigned int[] uints) Places an unsigned int array into the IntBuffer b.static IntBufferputUnsigned(IntBuffer b, @org.checkerframework.checker.signedness.qual.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, @org.checkerframework.checker.signedness.qual.Unsigned int uint) Places an unsigned int into the IntBuffer b at i.static ByteBufferputUnsignedInt(ByteBuffer b, @org.checkerframework.checker.signedness.qual.Unsigned int uint) Places an unsigned int into the ByteBuffer b.static ByteBufferputUnsignedInt(ByteBuffer b, int i, @org.checkerframework.checker.signedness.qual.Unsigned int uint) Places an unsigned int into the ByteBuffer b at i.static ByteBufferputUnsignedLong(ByteBuffer b, int i, @org.checkerframework.checker.signedness.qual.Unsigned long ulong) Places an unsigned long into the ByteBuffer b at i.static ByteBufferputUnsignedShort(ByteBuffer b, @org.checkerframework.checker.signedness.qual.Unsigned short ushort) Places an unsigned short into the ByteBuffer b.static ByteBufferputUnsignedShort(ByteBuffer b, int i, @org.checkerframework.checker.signedness.qual.Unsigned short ushort) Places an unsigned short into the ByteBuffer b at i.static voidreadFullyUnsigned(RandomAccessFile f, @org.checkerframework.checker.signedness.qual.Unsigned byte[] b) Reads a file fully into an unsigned byte array.static intreadUnsigned(RandomAccessFile f, @org.checkerframework.checker.signedness.qual.Unsigned byte[] b, int off, int len) Reads up tolenbytes of data from this file into an unsigned array of bytes.static @org.checkerframework.checker.signedness.qual.Unsigned charReads an unsigned char from the RandomAccessFile f.static @org.checkerframework.checker.signedness.qual.Unsigned intReads an unsigned int from the RandomAccessFile f.static @org.checkerframework.checker.signedness.qual.Unsigned longReads an unsigned long from the RandomAccessFile f.static @org.checkerframework.checker.signedness.qual.Unsigned shortshortFromDouble(double d) Returns an unsigned short representing the same value as the double.static @org.checkerframework.checker.signedness.qual.Unsigned shortshortFromFloat(float f) Returns an unsigned short representing the same value as the float.static doubletoDouble(@org.checkerframework.checker.signedness.qual.Unsigned byte b) Returns a double representing the same value as the unsigned byte.static doubletoDouble(@org.checkerframework.checker.signedness.qual.Unsigned int i) Returns a double representing the same value as the unsigned int.static doubletoDouble(@org.checkerframework.checker.signedness.qual.Unsigned long l) Returns a double representing the same value as the unsigned long.static doubletoDouble(@org.checkerframework.checker.signedness.qual.Unsigned short s) Returns a double representing the same value as the unsigned short.static floattoFloat(@org.checkerframework.checker.signedness.qual.Unsigned byte b) Returns a float representing the same value as the unsigned byte.static floattoFloat(@org.checkerframework.checker.signedness.qual.Unsigned int i) Returns a float representing the same value as the unsigned int.static floattoFloat(@org.checkerframework.checker.signedness.qual.Unsigned long l) Returns a float representing the same value as the unsigned long.static floattoFloat(@org.checkerframework.checker.signedness.qual.Unsigned short s) Returns a float representing the same value as the unsigned short.static @org.checkerframework.checker.signedness.qual.Unsigned inttoUnsignedInt(@org.checkerframework.checker.signedness.qual.Unsigned char c) Returns an unsigned int representing the same value as an unsigned char.static @org.checkerframework.checker.signedness.qual.Unsigned longtoUnsignedLong(@org.checkerframework.checker.signedness.qual.Unsigned char c) Returns an unsigned long representing the same value as an unsigned char.static @org.checkerframework.checker.signedness.qual.Unsigned shorttoUnsignedShort(@org.checkerframework.checker.signedness.qual.Unsigned byte b) Returns an unsigned short representing the same value as an unsigned byte.static @org.checkerframework.checker.signedness.qual.Unsigned shorttoUnsignedShort(@org.checkerframework.checker.signedness.qual.Unsigned char c) Returns an unsigned short representing the same value as an unsigned char.static StringtoUnsignedString(@org.checkerframework.checker.signedness.qual.Unsigned byte b) Produces a string representation of the unsigned byte b.static StringtoUnsignedString(@org.checkerframework.checker.signedness.qual.Unsigned byte b, int radix) Produces a string representation of the unsigned byte b in base radix.static StringtoUnsignedString(@org.checkerframework.checker.signedness.qual.Unsigned short s) Produces a string representation of the unsigned short s.static StringtoUnsignedString(@org.checkerframework.checker.signedness.qual.Unsigned short s, int radix) Produces a string representation of the unsigned short s in base radix.static ByteBufferwrapUnsigned(@org.checkerframework.checker.signedness.qual.Unsigned byte[] array) Wraps an unsigned byte array into a ByteBuffer.static ByteBufferwrapUnsigned(@org.checkerframework.checker.signedness.qual.Unsigned byte[] array, int offset, int length) Wraps an unsigned byte array into a ByteBuffer.static voidwriteUnsigned(RandomAccessFile f, @org.checkerframework.checker.signedness.qual.Unsigned byte[] bs, int off, int len) Writes len unsigned bytes to the RandomAccessFile f at offset off.static voidwriteUnsignedByte(RandomAccessFile f, @org.checkerframework.checker.signedness.qual.Unsigned byte b) Writes an unsigned byte to the RandomAccessFile f.static voidwriteUnsignedChar(RandomAccessFile f, @org.checkerframework.checker.signedness.qual.Unsigned char c) Writes an unsigned char to the RandomAccessFile f.static voidwriteUnsignedInt(RandomAccessFile f, @org.checkerframework.checker.signedness.qual.Unsigned int i) Writes an unsigned byte to the RandomAccessFile f.static voidwriteUnsignedLong(RandomAccessFile f, @org.checkerframework.checker.signedness.qual.Unsigned long l) Writes an unsigned byte to the RandomAccessFile f.static voidwriteUnsignedShort(RandomAccessFile f, @org.checkerframework.checker.signedness.qual.Unsigned short s) Writes an unsigned short to the RandomAccessFile f.
- 
Method Details- 
wrapUnsignedpublic static ByteBuffer wrapUnsigned(@org.checkerframework.checker.signedness.qual.Unsigned byte[] array) 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.
- 
wrapUnsignedpublic static ByteBuffer wrapUnsigned(@org.checkerframework.checker.signedness.qual.Unsigned byte[] array, int offset, int length) 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.
- 
getUnsignedIntpublic static @org.checkerframework.checker.signedness.qual.Unsigned int getUnsignedInt(ByteBuffer b) Gets an unsigned int from the ByteBuffer b. This method is a wrapper aroundgetInt(), but assumes that the result should be interpreted as unsigned.
- 
getUnsignedShortpublic static @org.checkerframework.checker.signedness.qual.Unsigned short getUnsignedShort(ByteBuffer b) Gets an unsigned short from the ByteBuffer b. This method is a wrapper aroundgetShort(), but assumes that the result should be interpreted as unsigned.
- 
getUnsignedGets an unsigned byte from the ByteBuffer b. This method is a wrapper aroundget(), but assumes that the result should be interpreted as unsigned.
- 
getUnsignedpublic static @org.checkerframework.checker.signedness.qual.Unsigned byte getUnsigned(ByteBuffer b, int i) 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.
- 
getUnsignedPopulates 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.
- 
putUnsignedpublic static ByteBuffer putUnsigned(ByteBuffer b, @org.checkerframework.checker.signedness.qual.Unsigned byte ubyte) 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.
- 
putUnsignedpublic static ByteBuffer putUnsigned(ByteBuffer b, int i, @org.checkerframework.checker.signedness.qual.Unsigned byte ubyte) 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.
- 
putUnsignedpublic static IntBuffer putUnsigned(IntBuffer b, @org.checkerframework.checker.signedness.qual.Unsigned int uint) Places an unsigned int into the IntBuffer b. This method is a wrapper aroundput(int), but assumes that the input should be interpreted as unsigned.
- 
putUnsignedpublic static IntBuffer putUnsigned(IntBuffer b, int i, @org.checkerframework.checker.signedness.qual.Unsigned int uint) 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.
- 
putUnsignedpublic static IntBuffer putUnsigned(IntBuffer b, @org.checkerframework.checker.signedness.qual.Unsigned int[] uints) 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.
- 
putUnsignedpublic static IntBuffer putUnsigned(IntBuffer b, @org.checkerframework.checker.signedness.qual.Unsigned int[] uints, int i, int l) 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.
- 
getUnsignedpublic static @org.checkerframework.checker.signedness.qual.Unsigned int getUnsigned(IntBuffer b, int i) Gets an unsigned int from the IntBuffer b at i. This method is a wrapper aroundget(int), but assumes that the output should be interpreted as unsigned.
- 
putUnsignedShortpublic static ByteBuffer putUnsignedShort(ByteBuffer b, @org.checkerframework.checker.signedness.qual.Unsigned short ushort) 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.
- 
putUnsignedShortpublic static ByteBuffer putUnsignedShort(ByteBuffer b, int i, @org.checkerframework.checker.signedness.qual.Unsigned short ushort) 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.
- 
putUnsignedIntpublic static ByteBuffer putUnsignedInt(ByteBuffer b, @org.checkerframework.checker.signedness.qual.Unsigned int uint) 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.
- 
putUnsignedIntpublic static ByteBuffer putUnsignedInt(ByteBuffer b, int i, @org.checkerframework.checker.signedness.qual.Unsigned int uint) 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.
- 
putUnsignedLongpublic static ByteBuffer putUnsignedLong(ByteBuffer b, int i, @org.checkerframework.checker.signedness.qual.Unsigned long ulong) 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.
- 
readUnsignedCharpublic static @org.checkerframework.checker.signedness.qual.Unsigned char readUnsignedChar(RandomAccessFile f) throws IOException 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
 
- 
readUnsignedIntpublic static @org.checkerframework.checker.signedness.qual.Unsigned int readUnsignedInt(RandomAccessFile f) throws IOException 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
 
- 
readUnsignedLongpublic static @org.checkerframework.checker.signedness.qual.Unsigned long readUnsignedLong(RandomAccessFile f) throws IOException 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
 
- 
readUnsignedpublic static int readUnsigned(RandomAccessFile f, @org.checkerframework.checker.signedness.qual.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
 
- 
readFullyUnsignedpublic static void readFullyUnsigned(RandomAccessFile f, @org.checkerframework.checker.signedness.qual.Unsigned byte[] b) throws IOException 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
 
- 
writeUnsignedpublic static void writeUnsigned(RandomAccessFile f, @org.checkerframework.checker.signedness.qual.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
 
- 
writeUnsignedBytepublic static void writeUnsignedByte(RandomAccessFile f, @org.checkerframework.checker.signedness.qual.Unsigned byte b) throws IOException 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
 
- 
writeUnsignedCharpublic static void writeUnsignedChar(RandomAccessFile f, @org.checkerframework.checker.signedness.qual.Unsigned char c) throws IOException 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
 
- 
writeUnsignedShortpublic static void writeUnsignedShort(RandomAccessFile f, @org.checkerframework.checker.signedness.qual.Unsigned short s) throws IOException 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
 
- 
writeUnsignedIntpublic static void writeUnsignedInt(RandomAccessFile f, @org.checkerframework.checker.signedness.qual.Unsigned int i) throws IOException 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
 
- 
writeUnsignedLongpublic static void writeUnsignedLong(RandomAccessFile f, @org.checkerframework.checker.signedness.qual.Unsigned long l) throws IOException 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
 
- 
getUnsignedpublic static void getUnsigned(ByteBuffer b, @org.checkerframework.checker.signedness.qual.Unsigned byte[] bs) 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.
- 
compareUnsignedpublic static int compareUnsigned(@org.checkerframework.checker.signedness.qual.Unsigned short x, @org.checkerframework.checker.signedness.qual.Unsigned short y) Compares two unsigned shorts x and y.In Java 11 or later, use Short.compareUnsigned. - Parameters:
- x- the first value to compare
- y- the second value to compare
- Returns:
- a negative number iff x < y, a positive number iff x > y, and zero iff x == y.
 
- 
compareUnsignedpublic static int compareUnsigned(@org.checkerframework.checker.signedness.qual.Unsigned byte x, @org.checkerframework.checker.signedness.qual.Unsigned byte y) Compares two unsigned bytes x and y.In Java 11 or later, use Byte.compareUnsigned. - Parameters:
- x- the first value to compare
- y- the second value to compare
- Returns:
- a negative number iff x < y, a positive number iff x > y, and zero iff x == y.
 
- 
toUnsignedStringpublic static String toUnsignedString(@org.checkerframework.checker.signedness.qual.Unsigned short s) Produces a string representation of the unsigned short s.
- 
toUnsignedStringpublic static String toUnsignedString(@org.checkerframework.checker.signedness.qual.Unsigned short s, int radix) Produces a string representation of the unsigned short s in base radix.
- 
toUnsignedStringpublic static String toUnsignedString(@org.checkerframework.checker.signedness.qual.Unsigned byte b) Produces a string representation of the unsigned byte b.
- 
toUnsignedStringpublic static String toUnsignedString(@org.checkerframework.checker.signedness.qual.Unsigned byte b, int radix) Produces a string representation of the unsigned byte b in base radix.
- 
toUnsignedShortpublic static @org.checkerframework.checker.signedness.qual.Unsigned short toUnsignedShort(@org.checkerframework.checker.signedness.qual.Unsigned byte b) Returns an unsigned short representing the same value as an unsigned byte.
- 
toUnsignedLongpublic static @org.checkerframework.checker.signedness.qual.Unsigned long toUnsignedLong(@org.checkerframework.checker.signedness.qual.Unsigned char c) Returns an unsigned long representing the same value as an unsigned char.
- 
toUnsignedIntpublic static @org.checkerframework.checker.signedness.qual.Unsigned int toUnsignedInt(@org.checkerframework.checker.signedness.qual.Unsigned char c) Returns an unsigned int representing the same value as an unsigned char.
- 
toUnsignedShortpublic static @org.checkerframework.checker.signedness.qual.Unsigned short toUnsignedShort(@org.checkerframework.checker.signedness.qual.Unsigned char c) Returns an unsigned short representing the same value as an unsigned char.
- 
toFloatpublic static float toFloat(@org.checkerframework.checker.signedness.qual.Unsigned byte b) Returns a float representing the same value as the unsigned byte.
- 
toFloatpublic static float toFloat(@org.checkerframework.checker.signedness.qual.Unsigned short s) Returns a float representing the same value as the unsigned short.
- 
toFloatpublic static float toFloat(@org.checkerframework.checker.signedness.qual.Unsigned int i) Returns a float representing the same value as the unsigned int.
- 
toFloatpublic static float toFloat(@org.checkerframework.checker.signedness.qual.Unsigned long l) Returns a float representing the same value as the unsigned long.
- 
toDoublepublic static double toDouble(@org.checkerframework.checker.signedness.qual.Unsigned byte b) Returns a double representing the same value as the unsigned byte.
- 
toDoublepublic static double toDouble(@org.checkerframework.checker.signedness.qual.Unsigned short s) Returns a double representing the same value as the unsigned short.
- 
toDoublepublic static double toDouble(@org.checkerframework.checker.signedness.qual.Unsigned int i) Returns a double representing the same value as the unsigned int.
- 
toDoublepublic static double toDouble(@org.checkerframework.checker.signedness.qual.Unsigned long l) Returns a double representing the same value as the unsigned long.
- 
byteFromFloatpublic static @org.checkerframework.checker.signedness.qual.Unsigned byte byteFromFloat(float f) Returns an unsigned byte representing the same value as the float.
- 
shortFromFloatpublic static @org.checkerframework.checker.signedness.qual.Unsigned short shortFromFloat(float f) Returns an unsigned short representing the same value as the float.
- 
intFromFloatpublic static @org.checkerframework.checker.signedness.qual.Unsigned int intFromFloat(float f) Returns an unsigned int representing the same value as the float.
- 
longFromFloatpublic static @org.checkerframework.checker.signedness.qual.Unsigned long longFromFloat(float f) Returns an unsigned long representing the same value as the float.
- 
byteFromDoublepublic static @org.checkerframework.checker.signedness.qual.Unsigned byte byteFromDouble(double d) Returns an unsigned byte representing the same value as the double.
- 
shortFromDoublepublic static @org.checkerframework.checker.signedness.qual.Unsigned short shortFromDouble(double d) Returns an unsigned short representing the same value as the double.
- 
intFromDoublepublic static @org.checkerframework.checker.signedness.qual.Unsigned int intFromDouble(double d) Returns an unsigned int representing the same value as the double.
- 
longFromDoublepublic static @org.checkerframework.checker.signedness.qual.Unsigned long longFromDouble(double d) Returns an unsigned long representing the same value as the double.
 
-