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 byte
byteFromDouble
(double d) Returns an unsigned byte representing the same value as the double.static @Unsigned byte
byteFromFloat
(float f) Returns an unsigned byte representing the same value as the float.static int
compareUnsigned
(@Unsigned byte x, @Unsigned byte y) Compares two unsigned bytes x and y.static int
compareUnsigned
(@Unsigned short x, @Unsigned short y) Compares two unsigned shorts x and y.static @Unsigned byte
Gets an unsigned byte from the ByteBuffer b.static void
getUnsigned
(ByteBuffer b, @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 @Unsigned byte
getUnsigned
(ByteBuffer b, int i) Gets an unsigned byte from the ByteBuffer b at i.static @Unsigned int
getUnsigned
(IntBuffer b, int i) Gets an unsigned int from the IntBuffer b at i.static @Unsigned int
Gets an unsigned int from the ByteBuffer b.static @Unsigned short
Gets an unsigned short from the ByteBuffer b.static @Unsigned int
intFromDouble
(double d) Returns an unsigned int representing the same value as the double.static @Unsigned int
intFromFloat
(float f) Returns an unsigned int representing the same value as the float.static @Unsigned long
longFromDouble
(double d) Returns an unsigned long representing the same value as the double.static @Unsigned long
longFromFloat
(float f) Returns an unsigned long representing the same value as the float.static ByteBuffer
putUnsigned
(ByteBuffer b, @Unsigned byte ubyte) Places an unsigned byte into the ByteBuffer b.static ByteBuffer
putUnsigned
(ByteBuffer b, int i, @Unsigned byte ubyte) Places an unsigned byte into the ByteBuffer b at i.static IntBuffer
putUnsigned
(IntBuffer b, @Unsigned int uint) Places an unsigned int into the IntBuffer b.static IntBuffer
putUnsigned
(IntBuffer b, @Unsigned int[] uints) Places an unsigned int array into the IntBuffer b.static IntBuffer
putUnsigned
(IntBuffer b, @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, @Unsigned int uint) Places an unsigned int into the IntBuffer b at i.static ByteBuffer
putUnsignedInt
(ByteBuffer b, @Unsigned int uint) Places an unsigned int into the ByteBuffer b.static ByteBuffer
putUnsignedInt
(ByteBuffer b, int i, @Unsigned int uint) Places an unsigned int into the ByteBuffer b at i.static ByteBuffer
putUnsignedLong
(ByteBuffer b, int i, @Unsigned long ulong) Places an unsigned long into the ByteBuffer b at i.static ByteBuffer
putUnsignedShort
(ByteBuffer b, @Unsigned short ushort) Places an unsigned short into the ByteBuffer b.static ByteBuffer
putUnsignedShort
(ByteBuffer b, int i, @Unsigned short ushort) Places an unsigned short into the ByteBuffer b at i.static void
readFullyUnsigned
(RandomAccessFile f, @Unsigned byte[] b) Reads a file fully into an unsigned byte array.static int
readUnsigned
(RandomAccessFile f, @Unsigned byte[] b, int off, int len) Reads up tolen
bytes of data from this file into an unsigned array of bytes.static @Unsigned char
Reads an unsigned char from the RandomAccessFile f.static @Unsigned int
Reads an unsigned int from the RandomAccessFile f.static @Unsigned long
Reads an unsigned long from the RandomAccessFile f.static @Unsigned short
shortFromDouble
(double d) Returns an unsigned short representing the same value as the double.static @Unsigned short
shortFromFloat
(float f) Returns an unsigned short representing the same value as the float.static double
Returns a double representing the same value as the unsigned byte.static double
Returns a double representing the same value as the unsigned int.static double
Returns a double representing the same value as the unsigned long.static double
Returns a double representing the same value as the unsigned short.static float
Returns a float representing the same value as the unsigned byte.static float
Returns a float representing the same value as the unsigned int.static float
Returns a float representing the same value as the unsigned long.static float
Returns a float representing the same value as the unsigned short.static @Unsigned int
toUnsignedInt
(@Unsigned char c) Returns an unsigned int representing the same value as an unsigned char.static @Unsigned long
toUnsignedLong
(@Unsigned char c) Returns an unsigned long representing the same value as an unsigned char.static @Unsigned short
toUnsignedShort
(@Unsigned byte b) Returns an unsigned short representing the same value as an unsigned byte.static @Unsigned short
toUnsignedShort
(@Unsigned char c) Returns an unsigned short representing the same value as an unsigned char.static String
toUnsignedString
(@Unsigned byte b) Produces a string representation of the unsigned byte b.static String
toUnsignedString
(@Unsigned byte b, int radix) Produces a string representation of the unsigned byte b in base radix.static String
toUnsignedString
(@Unsigned short s) Produces a string representation of the unsigned short s.static String
toUnsignedString
(@Unsigned short s, int radix) Produces a string representation of the unsigned short s in base radix.static ByteBuffer
wrapUnsigned
(@Unsigned byte[] array) Wraps an unsigned byte array into a ByteBuffer.static ByteBuffer
wrapUnsigned
(@Unsigned byte[] array, int offset, int length) Wraps an unsigned byte array into a ByteBuffer.static void
writeUnsigned
(RandomAccessFile f, @Unsigned byte[] bs, int off, int len) Writes len unsigned bytes to the RandomAccessFile f at offset off.static void
writeUnsignedByte
(RandomAccessFile f, @Unsigned byte b) Writes an unsigned byte to the RandomAccessFile f.static void
writeUnsignedChar
(RandomAccessFile f, @Unsigned char c) Writes an unsigned char to the RandomAccessFile f.static void
writeUnsignedInt
(RandomAccessFile f, @Unsigned int i) Writes an unsigned byte to the RandomAccessFile f.static void
writeUnsignedLong
(RandomAccessFile f, @Unsigned long l) Writes an unsigned byte to the RandomAccessFile f.static void
writeUnsignedShort
(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 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
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.
-