- java.lang.Object
-
- java.lang.Number
-
- de.bernd_michaely.x3f.types.UnsignedInteger
-
- All Implemented Interfaces:
Serializable
,Comparable<UnsignedInteger>
- Direct Known Subclasses:
UInt32
public class UnsignedInteger extends Number implements Comparable<UnsignedInteger>
Class for representing and handling of unsigned 32 Bit integer values.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected int
uint32
-
Constructor Summary
Constructors Constructor Description UnsignedInteger()
Initializes this unsigned integer with a value of zero.UnsignedInteger(int value)
Initializes this unsigned integer with a given value.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte
byteValue()
This method gets the low 7 bits and returns them as byte.int
compareTo(UnsignedInteger otherValue)
double
doubleValue()
boolean
equals(Object obj)
float
floatValue()
int
get16BitHigh()
Gets the high 16 bits and returns them as integer.int
get16BitLow()
Gets the low 16 bits and returns them as integer.String
getAsBitString()
Returns this value in a bit representation.byte[]
getAsByteArray()
Return this 32 bit value as little-endian four byte array.int
getByte(int index)
Returns the unsigned byte at the given index.int
getUnsignedByteValue()
Gets the lowest unsigned byte and returns it as integer.int
hashCode()
int
intValue()
This method gets the low 31 bits and returns them as integer.long
longValue()
Returns this value as long integer.short
shortValue()
This method gets the low 15 bits and returns them as short.String
toString()
-
-
-
Method Detail
-
compareTo
public int compareTo(UnsignedInteger otherValue)
- Specified by:
compareTo
in interfaceComparable<UnsignedInteger>
-
longValue
public long longValue()
Returns this value as long integer. The return value will be in the range of [0..232-1]. Note that this is the only method to return this value as an integral value without loss of the magnitude of the original 32 bit unsigned integer.
-
intValue
public int intValue()
This method gets the low 31 bits and returns them as integer. That is the value will be in the range of [0..231-1]. Note, that the value to hold is a 32 bit unsigned integer, but the return type is a 32 bit signed integer. So if the highest bit is expected to be set in this value, use thelongValue()
method instead.
-
shortValue
public short shortValue()
This method gets the low 15 bits and returns them as short. That is the value will be in the range of [0..215-1].- Overrides:
shortValue
in classNumber
- Returns:
- the low 15 bits as short
-
byteValue
public byte byteValue()
This method gets the low 7 bits and returns them as byte. That is the value will be in the range of [0..27-1].
-
floatValue
public float floatValue()
- Specified by:
floatValue
in classNumber
-
doubleValue
public double doubleValue()
- Specified by:
doubleValue
in classNumber
-
getByte
public int getByte(int index)
Returns the unsigned byte at the given index. That is the return value will be in the range of [0..28-1].- Parameters:
index
- the byte index, valid values are [0..3], 0 returns the least significant byte- Returns:
- the unsigned byte at the given index as int
- Throws:
IllegalArgumentException
- if index is invalid
-
getAsByteArray
public byte[] getAsByteArray()
Return this 32 bit value as little-endian four byte array.- Returns:
- this 32 bit value as little-endian four byte array
- Since:
- 2.0
-
getUnsignedByteValue
public int getUnsignedByteValue()
Gets the lowest unsigned byte and returns it as integer. That is the value will be in the range of [0..28-1].- Returns:
- the lowest unsigned byte
-
get16BitHigh
public int get16BitHigh()
Gets the high 16 bits and returns them as integer. That is the value will be in the range of [0..216-1].- Returns:
- the high 16 bits as integer
-
get16BitLow
public int get16BitLow()
Gets the low 16 bits and returns them as integer. That is the value will be in the range of [0..216-1].- Returns:
- the low 16 bits as integer
-
getAsBitString
public String getAsBitString()
Returns this value in a bit representation. This bits are written from the most to the least significant bit: "76543210 76543210 76543210 76543210":- Returns:
- this value as a binary string
-
-