Package ghidra.program.model.scalar
Class Scalar
java.lang.Object
ghidra.program.model.scalar.Scalar
The Scalar defines a immutable integer stored in an arbitrary number of bits (0..64), along
with a preferred signed-ness attribute.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
The size of this Scalar in bits.byte[]
Returns a byte array representing this Scalar.boolean
Returns the BigInteger representation of the value.long
Get the value as a signed long, where the highest bit of the value, if set, will be extended to fill the remaining bits of a java long.long
Get the value as an unsigned long.long
getValue()
Returns the value in its preferred signed-ness.long
getValue
(boolean signednessOverride) Returns the value, using the specified signedness. Equivalent to calling getSignedValue() or getUnsignedValue().int
hashCode()
boolean
isSigned()
Returns true if scalar was created as a signed valueboolean
testBit
(int n) Returns true if and only if the designated bit is set to one.toString()
Get a String representing this Scalar using the format defined by radix.
-
Constructor Details
-
Scalar
public Scalar(int bitLength, long value) Construct a new signed scalar object.- Parameters:
bitLength
- number of bits, valid values are 1..64, or 0 if value is also 0value
- value of the scalar, any bits that are set above bitLength will be ignored
-
Scalar
public Scalar(int bitLength, long value, boolean signed) Construct a new scalar.- Parameters:
bitLength
- number of bits, valid values are 1..64, or 0 if value is also 0value
- value of the scalar, any bits that are set above bitLength will be ignoredsigned
- true for a signed value, false for an unsigned value.
-
-
Method Details
-
isSigned
public boolean isSigned()Returns true if scalar was created as a signed value- Returns:
- boolean true if this scalar was created as a signed value, false if was created as unsigned
-
getSignedValue
public long getSignedValue()Get the value as a signed long, where the highest bit of the value, if set, will be extended to fill the remaining bits of a java long.- Returns:
- signed value
-
getUnsignedValue
public long getUnsignedValue()Get the value as an unsigned long.- Returns:
- unsigned value
-
getValue
public long getValue()Returns the value in its preferred signed-ness. SeegetSignedValue()
andgetUnsignedValue()
.- Returns:
- value, as either signed or unsigned, depending on how this instance was created
-
getValue
public long getValue(boolean signednessOverride) Returns the value, using the specified signedness. Equivalent to calling getSignedValue() or getUnsignedValue().- Parameters:
signednessOverride
- true for a signed value, false for an unsigned value- Returns:
- the value, using the specified signedness. Equivalent to calling getSignedValue() or getUnsignedValue()
-
getBigInteger
Returns the BigInteger representation of the value.- Returns:
- new BigInteger representation of the value
-
byteArrayValue
public byte[] byteArrayValue()Returns a byte array representing this Scalar. The size of the byte array is the number of bytes required to hold the number of bits returned by
bitLength()
.- Returns:
- a big-endian byte array containing the bits in this Scalar.
-
equals
-
hashCode
public int hashCode() -
bitLength
public int bitLength()The size of this Scalar in bits. This is constant for a Scalar. It is not dependent on the particular value of the scalar. For example, a 16-bit Scalar should always return 16 regardless of the actual value held.
- Returns:
- the width of this Scalar.
-
testBit
public boolean testBit(int n) Returns true if and only if the designated bit is set to one. Computes ((this & (1<<n)) != 0). Bits are numbered 0..bitlength()-1 with 0 being the least significant bit.
- Parameters:
n
- the bit to test.- Returns:
- true if and only if the designated bit is set to one.
- Throws:
IndexOutOfBoundsException
- if n >= bitLength().
-
toString
Get a String representing this Scalar using the format defined by radix.
- Parameters:
radix
- an integer base to use in representing the number (only 2, 8, 10, 16 are valid). If 10 is specified, all remaining parameters are ignored.zeroPadded
- a boolean which if true will have the number left padded with 0 to the width necessary to hold the maximum value.showSign
- if true the '-' sign will be prepended for negative values, else value will be treated as an unsigned value and output without a sign.pre
- a String to append after the sign (if signed) but before the digits.post
- a String to append after the digits.- Returns:
- a String representation of this scalar.
- Throws:
IllegalArgumentException
- If radix is not valid.
-
toString
-