Class NumberFormatter

java.lang.Object
com.pnfsoftware.jeb.util.format.NumberFormatter

public class NumberFormatter extends Object
A number formatter, supporting formatting of immediates of variable sizes using different bases and other properties (e.g., signedness).

Notes:

  • maximum size: 64-bit
  • signedness: applicable to octal/decimal/hexadecimal bases only; N/A for binary or ASCII formatting
  • Constructor Details

    • NumberFormatter

      public NumberFormatter()
      Create a formatter using unsigned hexadecimal numbers with an h suffix.
    • NumberFormatter

      public NumberFormatter(NumberFormatter defaultNumberFormatter)
      Create a formatter by copying another formatter's settings.
      Parameters:
      defaultNumberFormatter - formatter whose settings should be copied
  • Method Details

    • getBase

      public NumberFormatter.Base getBase()
      Get the current rendering base.
      Returns:
      the rendering base
    • setBase

      public void setBase(NumberFormatter.Base base)
      Set the rendering base.
      Parameters:
      base - non-null rendering base
    • rotateBase

      public NumberFormatter.Base rotateBase()
      Rotate the rendering base to the next built-in base.
      Returns:
      the new rendering base
    • setSignedNumber

      public void setSignedNumber(boolean signedNumber)
      Set whether standard bases should render values as signed numbers.
      Parameters:
      signedNumber - true to treat values as signed when supported by the base
    • isSignedNumber

      public boolean isSignedNumber()
      Determine whether standard bases render values as signed numbers.
      Returns:
      true if signed-number rendering is enabled
    • setNotationType

      public void setNotationType(NumberFormatter.NotationType notationType)
      Set the notation style used for hexadecimal numbers.
      Parameters:
      notationType - non-null notation style
    • getNotationType

      public NumberFormatter.NotationType getNotationType()
      Get the notation style used for hexadecimal numbers.
      Returns:
      the notation style
    • format

      public String format(int bitsize, long rawValue)
      Format a number using the formatter's current settings.
      Parameters:
      bitsize - value size in bits; 8, 16, and 32 are masked to that width, other values are treated as 64
      rawValue - raw integer value
      Returns:
      the formatted number
    • format

      public String format(int bitsize, long rawValue, NumberFormatter.Base base, boolean treatAsSignedNumber)
      Format a number using explicit settings.
      Parameters:
      bitsize - value size in bits; 8, 16, and 32 are masked to that width, other values are treated as 64
      rawValue - raw integer value
      base - rendering base, or null to use the formatter's current base
      treatAsSignedNumber - true to render supported bases as signed numbers
      Returns:
      the formatted number