Class NumberFormatter
java.lang.Object
com.pnfsoftware.jeb.core.units.code.asm.render.NumberFormatter
A number formatter used to format immediates.
Notes:
- max 64-bit long
- signedness: applicable to octal/decimal/hexadecimal, N/A for binary/ascii
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumNotation type for hexadecimal bases.static enumRendering base. -
Constructor Summary
ConstructorsConstructorDescriptionCreate a hexadecimal unsigned number formatter.NumberFormatter(NumberFormatter defaultNumberFormatter) Create a number formatter by copying another formatter. -
Method Summary
Modifier and TypeMethodDescriptionformat(int bitsize, long rawValue) Format a number using the formatter's current settings.format(int bitsize, long rawValue, NumberFormatter.NumberBase base, boolean treatAsSignedNumber) Format a number.format(int bitsize, BigInteger rawValue) Format a large number using the formatter's current settings.format(int bitsize, BigInteger rawValue, NumberFormatter.NumberBase base, boolean treatAsSignedNumber) Trivial implementation of a BigInteger formatter.getBase()Retrieve the rendering base.Retrieve endianness.booleanDetermine whether positive rendering is forced for non-base-10 values.Retrieve the hexadecimal notation style.booleanDetermine whether a constants formatter override is set.booleanDetermine whether numbers are treated as signed.Rotate to the next rendering base.voidSet the rendering base.voidSet a constants formatter override.voidsetEndianness(Endianness endianness) Change endianness.voidsetForcePositiveRenderingForNonBase10(boolean enabled) Force positive rendering for non-base-10 values.voidsetHexaNotationType(NumberFormatter.HexaNotationType hexaNotationType) Set the hexadecimal notation style.voidsetSignedNumber(boolean signedNumber) Set whether numbers should be treated as signed.
-
Constructor Details
-
NumberFormatter
public NumberFormatter()Create a hexadecimal unsigned number formatter. -
NumberFormatter
Create a number formatter by copying another formatter.- Parameters:
defaultNumberFormatter- formatter to copy
-
-
Method Details
-
getBase
Retrieve the rendering base.- Returns:
- rendering base
-
setBase
Set the rendering base.- Parameters:
base- rendering base
-
rotateBase
Rotate to the next rendering base.- Returns:
- new rendering base
-
setSignedNumber
public void setSignedNumber(boolean signedNumber) Set whether numbers should be treated as signed.- Parameters:
signedNumber- true to render as signed
-
isSignedNumber
public boolean isSignedNumber()Determine whether numbers are treated as signed.- Returns:
- true if signed rendering is enabled
-
setHexaNotationType
Set the hexadecimal notation style.- Parameters:
hexaNotationType- hexadecimal notation style
-
getHexaNotationType
Retrieve the hexadecimal notation style.- Returns:
- hexadecimal notation style
-
getEndianness
Retrieve endianness. Use- Returns:
- endianness
-
setEndianness
Change endianness. Note that defaultNumberFormatterconsider that data is Little Endian ordered (meaning that ascii representation will be flipped in comparison to raw value).- Parameters:
endianness- endianness
-
setConstantsFormatterOverride
Set a constants formatter override.- Parameters:
cf- constants formatter, or null
-
hasConstantsFormatterOverride
public boolean hasConstantsFormatterOverride()Determine whether a constants formatter override is set.- Returns:
- true if an override is set
-
setForcePositiveRenderingForNonBase10
public void setForcePositiveRenderingForNonBase10(boolean enabled) Force positive rendering for non-base-10 values.- Parameters:
enabled- true to force positive rendering
-
getForcePositiveRenderingForNonBase10
public boolean getForcePositiveRenderingForNonBase10()Determine whether positive rendering is forced for non-base-10 values.- Returns:
- true if enabled
-
format
Format a number using the formatter's current settings.- Parameters:
bitsize- value size in bitsrawValue- raw value- Returns:
- formatted value
-
format
public String format(int bitsize, long rawValue, NumberFormatter.NumberBase base, boolean treatAsSignedNumber) Format a number.- Parameters:
bitsize- value size in bitsrawValue- raw valuebase- rendering basetreatAsSignedNumber- true to treat the value as signed- Returns:
- formatted value
-
format
Format a large number using the formatter's current settings.- Parameters:
bitsize- value size in bitsrawValue- raw value- Returns:
- formatted value
-
format
public String format(int bitsize, BigInteger rawValue, NumberFormatter.NumberBase base, boolean treatAsSignedNumber) Trivial implementation of a BigInteger formatter. Reverts to usingformat(int, long, NumberBase, boolean)if bitsize is<= 64.- Parameters:
bitsize- value size in bitsrawValue- raw valuebase- rendering basetreatAsSignedNumber- true to treat the value as signed- Returns:
- formatted value
-