Class Scalar

java.lang.Object
ghidra.program.model.scalar.Scalar
Direct Known Subclasses:
DWARFNumericAttribute

public class Scalar extends Object
The Scalar defines a immutable integer stored in an arbitrary number of bits (0..64), along with a preferred signed-ness attribute.
  • Constructor Summary

    Constructors
    Change
    Constructor
    Description
    Scalar(int bitLength, long value)
    Construct a new signed scalar object.
    Scalar(int bitLength, long value, boolean signed)
    Construct a new scalar.
  • Method Summary

    Change
    Modifier and Type
    Method
    Description
    int
    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
    Returns the value in its preferred signed-ness.
    NEW
    long
    getValue(boolean signednessOverride)
    Returns the value, using the specified signedness. Equivalent to calling getSignedValue() or getUnsignedValue().
    int
     
    boolean
    Returns true if scalar was created as a signed value
    boolean
    testBit(int n)
    Returns true if and only if the designated bit is set to one.
     
    toString(int radix, boolean zeroPadded, boolean showSign, String pre, String post)
    Get a String representing this Scalar using the format defined by radix.
    REMOVED
    Scalar
    newScalar(long newValue)
    Removed
    REMOVED
    int
    compareTo(Scalar other)
    Removed
    REMOVED
    Scalar
    add(long n)
    Removed
    REMOVED
    Scalar
    clearBit(int n)
    Removed
    REMOVED
    Scalar
    flipBit(int n)
    Removed
    REMOVED
    Scalar
    setBit(int n)
    Removed
    REMOVED
    Scalar
    shiftLeft(int n)
    Removed
    REMOVED
    Scalar
    shiftRight(int n)
    Removed
    REMOVED
    Scalar
    Removed
    REMOVED
    Scalar
    subtract(long n)
    Removed

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • 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 0
      value - 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 0
      value - value of the scalar, any bits that are set above bitLength will be ignored
      signed - 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. See getSignedValue() and getUnsignedValue().
      Returns:
      value, as either signed or unsigned, depending on how this instance was created
    • getValue NEW

      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

      public BigInteger 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

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • 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

      public String toString(int radix, boolean zeroPadded, boolean showSign, String pre, String post)

      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

      public String toString()
      Overrides:
      toString in class Object