For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).
hex
def hex(value: Scalar, /, *, prefix: StaticString = "0x") -> String
Returns the hexadecimal string representation of an integer.
The string is prefixed with "0x" by default and uses lowercase digits.
Negative values start with a minus sign, like -0xff.
For example:
print(hex(255)) # 0xff
print(hex(-255)) # -0xff
print(hex(255, prefix="")) # ff
Args:
- value (
Scalar): The integer value to format. - prefix (
StaticString): The prefix prepended to the digits (defaults to"0x").
Returns:
String: A string containing the hexadecimal representation of the value.
def hex[T: Intable, //](value: T, /, *, prefix: StaticString = "0x") -> String
Returns the hexadecimal string representation of a value.
The value is converted to Int and formatted in base 16, prefixed with
"0x" by default.
Parameters:
- T (
Intable): The type of the value. Must conform toIntable.
Args:
- value (
T): The value to format. - prefix (
StaticString): The prefix prepended to the digits (defaults to"0x").
Returns:
String: A string containing the hexadecimal representation of the value.
def hex(value: Scalar[DType.bool], /, *, prefix: StaticString = "0x") -> String
Returns the hexadecimal string representation of a bool value.
The bool is formatted as an integer, so the result is 0x0 or 0x1
with the default prefix.
Args:
- value (
Scalar[DType.bool]): The bool value to format. - prefix (
StaticString): The prefix prepended to the digits (defaults to"0x").
Returns:
String: A string containing the hexadecimal representation of the bool.