Class UnsignedInteger
java.lang.Object
java.lang.Number
com.google.common.primitives.UnsignedInteger
- All Implemented Interfaces:
Serializable, Comparable<UnsignedInteger>
@GwtCompatible
public final class UnsignedInteger
extends Number
implements Comparable<UnsignedInteger>
A wrapper class for unsigned
int values, supporting arithmetic operations.
In some cases, when speed is more important than code readability, it may be faster simply to
treat primitive int values as unsigned, using the methods from UnsignedInts.
See the Guava User Guide article on unsigned primitive utilities.
- Since:
- 11.0
- Author:
- Louis Wasserman
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final UnsignedIntegerstatic final UnsignedIntegerstatic final UnsignedInteger -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of thisUnsignedIntegeras aBigInteger.intcompareTo(UnsignedInteger other) Compares this unsigned integer to another unsigned integer.dividedBy(UnsignedInteger val) Returns the result of dividing this byval.doubleReturns the value of thisUnsignedIntegeras adouble, analogous to a widening primitive conversion frominttodouble, and correctly rounded.booleanfloatReturns the value of thisUnsignedIntegeras afloat, analogous to a widening primitive conversion frominttofloat, and correctly rounded.static UnsignedIntegerfromIntBits(int bits) Returns anUnsignedIntegercorresponding to a given bit representation.inthashCode()intintValue()Returns the value of thisUnsignedIntegeras anint.longReturns the value of thisUnsignedIntegeras along.minus(UnsignedInteger val) Returns the result of subtracting this andval.mod(UnsignedInteger val) Returns this modval.plus(UnsignedInteger val) Returns the result of adding this andval.times(UnsignedInteger val) Returns the result of multiplying this andval.toString()Returns a string representation of theUnsignedIntegervalue, in base 10.toString(int radix) Returns a string representation of theUnsignedIntegervalue, in baseradix.static UnsignedIntegervalueOf(long value) Returns anUnsignedIntegerthat is equal tovalue, if possible.static UnsignedIntegerReturns anUnsignedIntegerholding the value of the specifiedString, parsed as an unsignedintvalue.static UnsignedIntegerReturns anUnsignedIntegerholding the value of the specifiedString, parsed as an unsignedintvalue in the specified radix.static UnsignedIntegervalueOf(BigInteger value) Returns aUnsignedIntegerrepresenting the same value as the specifiedBigInteger.Methods inherited from class Number
byteValue, shortValue
-
Field Details
-
ZERO
-
ONE
-
MAX_VALUE
-
-
Method Details
-
fromIntBits
Returns anUnsignedIntegercorresponding to a given bit representation. The argument is interpreted as an unsigned 32-bit value. Specifically, the sign bit ofbitsis interpreted as a normal bit, and all other bits are treated as usual.If the argument is nonnegative, the returned result will be equal to
bits, otherwise, the result will be equal to2^32 + bits.To represent unsigned decimal constants, consider
valueOf(long)instead.- Since:
- 14.0
-
valueOf
Returns anUnsignedIntegerthat is equal tovalue, if possible. The inverse operation oflongValue(). -
valueOf
Returns aUnsignedIntegerrepresenting the same value as the specifiedBigInteger. This is the inverse operation ofbigIntegerValue().- Throws:
IllegalArgumentException- ifvalueis negative orvalue >= 2^32
-
valueOf
Returns anUnsignedIntegerholding the value of the specifiedString, parsed as an unsignedintvalue.- Throws:
NumberFormatException- if the string does not contain a parsable unsignedintvalue
-
valueOf
Returns anUnsignedIntegerholding the value of the specifiedString, parsed as an unsignedintvalue in the specified radix.- Throws:
NumberFormatException- if the string does not contain a parsable unsignedintvalue
-
plus
Returns the result of adding this andval. If the result would have more than 32 bits, returns the low 32 bits of the result.- Since:
- 14.0
-
minus
Returns the result of subtracting this andval. If the result would be negative, returns the low 32 bits of the result.- Since:
- 14.0
-
times
Returns the result of multiplying this andval. If the result would have more than 32 bits, returns the low 32 bits of the result.- Since:
- 14.0
-
dividedBy
Returns the result of dividing this byval.- Throws:
ArithmeticException- ifvalis zero- Since:
- 14.0
-
mod
Returns this modval.- Throws:
ArithmeticException- ifvalis zero- Since:
- 14.0
-
intValue
public int intValue()Returns the value of thisUnsignedIntegeras anint. This is an inverse operation tofromIntBits(int).Note that if this
UnsignedIntegerholds a value>= 2^31, the returned value will be equal tothis - 2^32. -
longValue
-
floatValue
public float floatValue()Returns the value of thisUnsignedIntegeras afloat, analogous to a widening primitive conversion frominttofloat, and correctly rounded.- Specified by:
floatValuein classNumber
-
doubleValue
public double doubleValue()Returns the value of thisUnsignedIntegeras adouble, analogous to a widening primitive conversion frominttodouble, and correctly rounded.- Specified by:
doubleValuein classNumber
-
bigIntegerValue
Returns the value of thisUnsignedIntegeras aBigInteger. -
compareTo
Compares this unsigned integer to another unsigned integer. Returns0if they are equal, a negative number ifthis < other, and a positive number ifthis > other.- Specified by:
compareToin interfaceComparable<UnsignedInteger>
-
hashCode
-
equals
-
toString
-
toString
Returns a string representation of theUnsignedIntegervalue, in baseradix. Ifradix < Character.MIN_RADIXorradix > Character.MAX_RADIX, the radix10is used.
-