Class LargeIntHandler
java.lang.Object
com.pnfsoftware.jeb.util.primitives.LargeIntHandler
Handler for large integers of a given maximum bitsize. Those objects are created through a
factory method.
-
Method Summary
Modifier and TypeMethodDescriptionadd(BigInteger a, BigInteger b) Add two signed values and truncate the result.and(BigInteger a, BigInteger b) Bitwise AND two values and truncate the result.clearbit(BigInteger a, int n) Clear a bit in a value and truncate the result.intcompare(BigInteger a, BigInteger b) Compare two signed values.intcompareU(BigInteger a, BigInteger b) Compare two unsigned values.static LargeIntHandlercreate(int bitsize) Create or retrieve a handler for a fixed integer bit size.Create a new big integer.div2S(BigInteger a, BigInteger b) Divide a double-width signed dividend by a signed divisor.div2U(BigInteger a, BigInteger b) Divide a double-width unsigned dividend by an unsigned divisor.divS(BigInteger a, BigInteger b) Divide two signed values and truncate the quotient.divU(BigInteger a, BigInteger b) Divide two unsigned values and truncate the quotient.intGet the fixed integer bit size.mul2S(BigInteger a, BigInteger b) Multiply two signed values and truncate the result to twice the handler bit size.mul2U(BigInteger a, BigInteger b) Multiply two unsigned values and truncate the result to twice the handler bit size.mulS(BigInteger a, BigInteger b) Multiply two signed values and truncate the result to the handler bit size.mulU(BigInteger a, BigInteger b) Multiply two unsigned values and truncate the result to the handler bit size.neg(BigInteger a) Negate a signed value and truncate the result.not(BigInteger a) Bitwise NOT a value and truncate the result.or(BigInteger a, BigInteger b) Bitwise OR two values and truncate the result.remS(BigInteger a, BigInteger b) Compute the signed remainder and truncate it.remU(BigInteger a, BigInteger b) Compute the unsigned remainder and truncate it.rol(BigInteger a, int n) Rotate left with a modulo-count.ror(BigInteger a, int n) Rotate right with a modulo-count.sar(BigInteger a, int n) Arithmetic shift right with a modulo-count.setbit(BigInteger a, int n) Set a bit in a value and truncate the result.shl(BigInteger a, int n) Shift left with a modulo-count.shr(BigInteger a, int n) Logical shift right with a modulo-count.sub(BigInteger a, BigInteger b) Subtract two signed values and truncate the result.booleantestbit(BigInteger a, int n) Test a bit in a value.Get the unsigned equivalent of the provided truncated integer.Format a value as an unsigned hexadecimal string.Truncate and store as a signed value.Truncate and store as a signed value.xor(BigInteger a, BigInteger b) Bitwise XOR two values and truncate the result.
-
Method Details
-
create
Create or retrieve a handler for a fixed integer bit size.- Parameters:
bitsize- integer bit size- Returns:
- a cached handler for the bit size
-
getBitsize
public int getBitsize()Get the fixed integer bit size.- Returns:
- the bit size
-
create
Create a new big integer. The client is responsible for making sure that the two-complement representation of the value fits withinbitsizebits.- Parameters:
val- string value (decimal, hex, or octal - with the right associated prefix or suffix)- Returns:
- the parsed value
-
truncate
Truncate and store as a signed value. The resulting integer 2-complement representation holds on at mostbitsizebits.- Parameters:
val- string value (decimal, hex, or octal - with the right associated prefix or suffix)- Returns:
- the truncated signed value
-
truncate
Truncate and store as a signed value. The resulting integer 2-complement representation holds on at mostbitsizebits.- Parameters:
v- value to truncate- Returns:
- the truncated signed value
-
toUnsigned
Get the unsigned equivalent of the provided truncated integer.Warning, this method is unsafe! The result may no longer be representable on bitsize bits.
- Parameters:
a- signed value- Returns:
- the unsigned equivalent
-
neg
Negate a signed value and truncate the result.- Parameters:
a- value to negate- Returns:
- the truncated result
-
add
Add two signed values and truncate the result.- Parameters:
a- first valueb- second value- Returns:
- the truncated result
-
sub
Subtract two signed values and truncate the result.- Parameters:
a- minuendb- subtrahend- Returns:
- the truncated result
-
mulS
Multiply two signed values and truncate the result to the handler bit size.- Parameters:
a- first valueb- second value- Returns:
- the truncated result
-
mulU
Multiply two unsigned values and truncate the result to the handler bit size.- Parameters:
a- first valueb- second value- Returns:
- the truncated result
-
mul2S
Multiply two signed values and truncate the result to twice the handler bit size.- Parameters:
a- first valueb- second value- Returns:
- the double-width truncated result
-
mul2U
Multiply two unsigned values and truncate the result to twice the handler bit size.- Parameters:
a- first valueb- second value- Returns:
- the double-width truncated result
-
divS
Divide two signed values and truncate the quotient.- Parameters:
a- dividendb- divisor- Returns:
- the truncated quotient
-
divU
Divide two unsigned values and truncate the quotient.- Parameters:
a- dividendb- divisor- Returns:
- the truncated quotient
-
remS
Compute the signed remainder and truncate it.- Parameters:
a- dividendb- divisor- Returns:
- the truncated remainder
-
remU
Compute the unsigned remainder and truncate it.- Parameters:
a- dividendb- divisor- Returns:
- the truncated remainder
-
div2S
Divide a double-width signed dividend by a signed divisor.- Parameters:
a- double-width dividendb- divisor- Returns:
- two elements: truncated quotient and truncated remainder
-
div2U
Divide a double-width unsigned dividend by an unsigned divisor.- Parameters:
a- double-width dividendb- divisor- Returns:
- two elements: truncated quotient and truncated remainder
-
and
Bitwise AND two values and truncate the result.- Parameters:
a- first valueb- second value- Returns:
- the truncated result
-
or
Bitwise OR two values and truncate the result.- Parameters:
a- first valueb- second value- Returns:
- the truncated result
-
not
Bitwise NOT a value and truncate the result.- Parameters:
a- value- Returns:
- the truncated result
-
xor
Bitwise XOR two values and truncate the result.- Parameters:
a- first valueb- second value- Returns:
- the truncated result
-
testbit
Test a bit in a value.- Parameters:
a- valuen- bit index- Returns:
- true if the bit is set
-
setbit
Set a bit in a value and truncate the result.- Parameters:
a- valuen- bit index- Returns:
- the truncated result
-
clearbit
Clear a bit in a value and truncate the result.- Parameters:
a- valuen- bit index- Returns:
- the truncated result
-
shl
Shift left with a modulo-count.- Parameters:
a- value to shiftn- shift count- Returns:
- the truncated result
-
shr
Logical shift right with a modulo-count.- Parameters:
a- value to shiftn- shift count- Returns:
- the truncated result
-
sar
Arithmetic shift right with a modulo-count.- Parameters:
a- value to shiftn- shift count- Returns:
- the truncated result
-
ror
Rotate right with a modulo-count.- Parameters:
a- value to rotaten- rotation count- Returns:
- the truncated result
-
rol
Rotate left with a modulo-count.- Parameters:
a- value to rotaten- rotation count- Returns:
- the truncated result
-
compare
Compare two signed values.- Parameters:
a- first valueb- second value- Returns:
- a negative value, zero, or a positive value if
ais respectively below, equal to, or aboveb
-
compareU
Compare two unsigned values.- Parameters:
a- first valueb- second value- Returns:
- a negative value, zero, or a positive value if
ais respectively below, equal to, or abovebin unsigned order
-
toUnsignedHexString
Format a value as an unsigned hexadecimal string.- Parameters:
v- value to format- Returns:
- the upper-case unsigned hexadecimal representation
-