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 @org.checkerframework.checker.signedness.qual.Unsigned byte
byteFromDouble
(double d) Returns an unsigned byte representing the same value as the double.static @org.checkerframework.checker.signedness.qual.Unsigned byte
byteFromFloat
(float f) Returns an unsigned byte representing the same value as the float.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.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.static @org.checkerframework.checker.signedness.qual.Unsigned byte
Gets an unsigned byte from the ByteBuffer b.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.static ByteBuffer
getUnsigned
(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 byte
getUnsigned
(ByteBuffer b, int i) Gets an unsigned byte from the ByteBuffer b at i.static @org.checkerframework.checker.signedness.qual.Unsigned int
getUnsigned
(IntBuffer b, int i) Gets an unsigned int from the IntBuffer b at i.static @org.checkerframework.checker.signedness.qual.Unsigned int
Gets an unsigned int from the ByteBuffer b.static @org.checkerframework.checker.signedness.qual.Unsigned short
Gets an unsigned short from the ByteBuffer b.static @org.checkerframework.checker.signedness.qual.Unsigned int
intFromDouble
(double d) Returns an unsigned int representing the same value as the double.static @org.checkerframework.checker.signedness.qual.Unsigned int
intFromFloat
(float f) Returns an unsigned int representing the same value as the float.static @org.checkerframework.checker.signedness.qual.Unsigned long
longFromDouble
(double d) Returns an unsigned long representing the same value as the double.static @org.checkerframework.checker.signedness.qual.Unsigned long
longFromFloat
(float f) Returns an unsigned long representing the same value as the float.static ByteBuffer
putUnsigned
(ByteBuffer b, @org.checkerframework.checker.signedness.qual.Unsigned byte ubyte) Places an unsigned byte into the ByteBuffer b.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.static IntBuffer
putUnsigned
(IntBuffer b, @org.checkerframework.checker.signedness.qual.Unsigned int uint) Places an unsigned int into the IntBuffer b.static IntBuffer
putUnsigned
(IntBuffer b, @org.checkerframework.checker.signedness.qual.Unsigned int[] uints) Places an unsigned int array into the IntBuffer b.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.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.static ByteBuffer
putUnsignedInt
(ByteBuffer b, @org.checkerframework.checker.signedness.qual.Unsigned int uint) Places an unsigned int into the ByteBuffer b.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.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.static ByteBuffer
putUnsignedShort
(ByteBuffer b, @org.checkerframework.checker.signedness.qual.Unsigned short ushort) Places an unsigned short into the ByteBuffer b.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.static void
readFullyUnsigned
(RandomAccessFile f, @org.checkerframework.checker.signedness.qual.Unsigned byte[] b) Reads a file fully into an unsigned byte array.static int
readUnsigned
(RandomAccessFile f, @org.checkerframework.checker.signedness.qual.Unsigned byte[] b, int off, int len) Reads up tolen
bytes of data from this file into an unsigned array of bytes.static @org.checkerframework.checker.signedness.qual.Unsigned char
Reads an unsigned char from the RandomAccessFile f.static @org.checkerframework.checker.signedness.qual.Unsigned int
Reads an unsigned int from the RandomAccessFile f.static @org.checkerframework.checker.signedness.qual.Unsigned long
Reads an unsigned long from the RandomAccessFile f.static @org.checkerframework.checker.signedness.qual.Unsigned short
shortFromDouble
(double d) Returns an unsigned short representing the same value as the double.static @org.checkerframework.checker.signedness.qual.Unsigned short
shortFromFloat
(float f) Returns an unsigned short representing the same value as the float.static double
toDouble
(@org.checkerframework.checker.signedness.qual.Unsigned byte b) Returns a double representing the same value as the unsigned byte.static double
toDouble
(@org.checkerframework.checker.signedness.qual.Unsigned int i) Returns a double representing the same value as the unsigned int.static double
toDouble
(@org.checkerframework.checker.signedness.qual.Unsigned long l) Returns a double representing the same value as the unsigned long.static double
toDouble
(@org.checkerframework.checker.signedness.qual.Unsigned short s) Returns a double representing the same value as the unsigned short.static float
toFloat
(@org.checkerframework.checker.signedness.qual.Unsigned byte b) Returns a float representing the same value as the unsigned byte.static float
toFloat
(@org.checkerframework.checker.signedness.qual.Unsigned int i) Returns a float representing the same value as the unsigned int.static float
toFloat
(@org.checkerframework.checker.signedness.qual.Unsigned long l) Returns a float representing the same value as the unsigned long.static float
toFloat
(@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 int
toUnsignedInt
(@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 long
toUnsignedLong
(@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 short
toUnsignedShort
(@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 short
toUnsignedShort
(@org.checkerframework.checker.signedness.qual.Unsigned char c) Returns an unsigned short representing the same value as an unsigned char.static String
toUnsignedString
(@org.checkerframework.checker.signedness.qual.Unsigned byte b) Produces a string representation of the unsigned byte b.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.static String
toUnsignedString
(@org.checkerframework.checker.signedness.qual.Unsigned short s) Produces a string representation of the unsigned short s.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.static ByteBuffer
wrapUnsigned
(@org.checkerframework.checker.signedness.qual.Unsigned byte[] array) Wraps an unsigned byte array into a ByteBuffer.static ByteBuffer
wrapUnsigned
(@org.checkerframework.checker.signedness.qual.Unsigned byte[] array, int offset, int length) Wraps an unsigned byte array into a ByteBuffer.static void
writeUnsigned
(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 void
writeUnsignedByte
(RandomAccessFile f, @org.checkerframework.checker.signedness.qual.Unsigned byte b) Writes an unsigned byte to the RandomAccessFile f.static void
writeUnsignedChar
(RandomAccessFile f, @org.checkerframework.checker.signedness.qual.Unsigned char c) Writes an unsigned char to the RandomAccessFile f.static void
writeUnsignedInt
(RandomAccessFile f, @org.checkerframework.checker.signedness.qual.Unsigned int i) Writes an unsigned byte to the RandomAccessFile f.static void
writeUnsignedLong
(RandomAccessFile f, @org.checkerframework.checker.signedness.qual.Unsigned long l) Writes an unsigned byte to the RandomAccessFile f.static void
writeUnsignedShort
(RandomAccessFile f, @org.checkerframework.checker.signedness.qual.Unsigned short s) Writes an unsigned short to the RandomAccessFile f.
-
Method Details
-
wrapUnsigned
public 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. -
wrapUnsigned
public 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. -
getUnsignedInt
public 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. -
getUnsignedShort
public 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. -
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
public 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. -
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
public 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. -
putUnsigned
public 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. -
putUnsigned
public 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. -
putUnsigned
public 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. -
putUnsigned
public 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. -
putUnsigned
public 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. -
getUnsigned
public 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. -
putUnsignedShort
public 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. -
putUnsignedShort
public 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. -
putUnsignedInt
public 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. -
putUnsignedInt
public 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. -
putUnsignedLong
public 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. -
readUnsignedChar
public 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
-
readUnsignedInt
public 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
-
readUnsignedLong
public 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
-
readUnsigned
public static int readUnsigned(RandomAccessFile f, @org.checkerframework.checker.signedness.qual.Unsigned byte[] b, int off, int len) throws IOException Reads up tolen
bytes 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
public 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
-
writeUnsigned
public 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
-
writeUnsignedByte
public 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
-
writeUnsignedChar
public 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
-
writeUnsignedShort
public 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
-
writeUnsignedInt
public 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
-
writeUnsignedLong
public 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
-
getUnsigned
public 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. -
compareUnsigned
public 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 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
public 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 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
public static String toUnsignedString(@org.checkerframework.checker.signedness.qual.Unsigned short s) Produces a string representation of the unsigned short s. -
toUnsignedString
public 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. -
toUnsignedString
public static String toUnsignedString(@org.checkerframework.checker.signedness.qual.Unsigned byte b) Produces a string representation of the unsigned byte b. -
toUnsignedString
public 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. -
toUnsignedShort
public 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. -
toUnsignedLong
public 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. -
toUnsignedInt
public 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. -
toUnsignedShort
public 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. -
toFloat
public static float toFloat(@org.checkerframework.checker.signedness.qual.Unsigned byte b) Returns a float representing the same value as the unsigned byte. -
toFloat
public static float toFloat(@org.checkerframework.checker.signedness.qual.Unsigned short s) Returns a float representing the same value as the unsigned short. -
toFloat
public static float toFloat(@org.checkerframework.checker.signedness.qual.Unsigned int i) Returns a float representing the same value as the unsigned int. -
toFloat
public static float toFloat(@org.checkerframework.checker.signedness.qual.Unsigned long l) Returns a float representing the same value as the unsigned long. -
toDouble
public static double toDouble(@org.checkerframework.checker.signedness.qual.Unsigned byte b) Returns a double representing the same value as the unsigned byte. -
toDouble
public static double toDouble(@org.checkerframework.checker.signedness.qual.Unsigned short s) Returns a double representing the same value as the unsigned short. -
toDouble
public static double toDouble(@org.checkerframework.checker.signedness.qual.Unsigned int i) Returns a double representing the same value as the unsigned int. -
toDouble
public static double toDouble(@org.checkerframework.checker.signedness.qual.Unsigned long l) Returns a double representing the same value as the unsigned long. -
byteFromFloat
public static @org.checkerframework.checker.signedness.qual.Unsigned byte byteFromFloat(float f) Returns an unsigned byte representing the same value as the float. -
shortFromFloat
public static @org.checkerframework.checker.signedness.qual.Unsigned short shortFromFloat(float f) Returns an unsigned short representing the same value as the float. -
intFromFloat
public static @org.checkerframework.checker.signedness.qual.Unsigned int intFromFloat(float f) Returns an unsigned int representing the same value as the float. -
longFromFloat
public static @org.checkerframework.checker.signedness.qual.Unsigned long longFromFloat(float f) Returns an unsigned long representing the same value as the float. -
byteFromDouble
public static @org.checkerframework.checker.signedness.qual.Unsigned byte byteFromDouble(double d) Returns an unsigned byte representing the same value as the double. -
shortFromDouble
public static @org.checkerframework.checker.signedness.qual.Unsigned short shortFromDouble(double d) Returns an unsigned short representing the same value as the double. -
intFromDouble
public static @org.checkerframework.checker.signedness.qual.Unsigned int intFromDouble(double d) Returns an unsigned int representing the same value as the double. -
longFromDouble
public static @org.checkerframework.checker.signedness.qual.Unsigned long longFromDouble(double d) Returns an unsigned long representing the same value as the double.
-