Package com.pnfsoftware.jeb.util.format
Class NumberFormatter
java.lang.Object
com.pnfsoftware.jeb.util.format.NumberFormatter
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumRendering base.static enumNotation type for hexadecimal bases. -
Constructor Summary
ConstructorsConstructorDescriptionCreate a formatter using unsigned hexadecimal numbers with anhsuffix.NumberFormatter(NumberFormatter defaultNumberFormatter) Create a formatter by copying another formatter's settings. -
Method Summary
Modifier and TypeMethodDescriptionformat(int bitsize, long rawValue) Format a number using the formatter's current settings.format(int bitsize, long rawValue, NumberFormatter.Base base, boolean treatAsSignedNumber) Format a number using explicit settings.getBase()Get the current rendering base.Get the notation style used for hexadecimal numbers.booleanDetermine whether standard bases render values as signed numbers.Rotate the rendering base to the next built-in base.voidsetBase(NumberFormatter.Base base) Set the rendering base.voidsetNotationType(NumberFormatter.NotationType notationType) Set the notation style used for hexadecimal numbers.voidsetSignedNumber(boolean signedNumber) Set whether standard bases should render values as signed numbers.
-
Constructor Details
-
NumberFormatter
public NumberFormatter()Create a formatter using unsigned hexadecimal numbers with anhsuffix. -
NumberFormatter
Create a formatter by copying another formatter's settings.- Parameters:
defaultNumberFormatter- formatter whose settings should be copied
-
-
Method Details
-
getBase
Get the current rendering base.- Returns:
- the rendering base
-
setBase
Set the rendering base.- Parameters:
base- non-null rendering 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
Set the notation style used for hexadecimal numbers.- Parameters:
notationType- non-null notation style
-
getNotationType
Get the notation style used for hexadecimal numbers.- Returns:
- the notation style
-
format
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 64rawValue- 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 64rawValue- raw integer valuebase- rendering base, or null to use the formatter's current basetreatAsSignedNumber- true to render supported bases as signed numbers- Returns:
- the formatted number
-