hex

hex(n, [pad])

Convert an integer to a hexadecimal string, optionally specifying a number of digits to pad to.

Examples

  • Convert an integer to a hexadecimal string:

    julia> hex(15)
    "f"

    This example converts the decimal number 15 to its hexadecimal representation, which is "f".

  • Specify a number of digits to pad to:
    julia> hex(10, 4)
    "000a"

    In this example, the decimal number 10 is converted to hexadecimal with a padding of 4 digits. The resulting hexadecimal string is "000a".

julia> hex(255, 2)
"ff"

Here, the decimal number 255 is converted to hexadecimal with a padding of 2 digits. The resulting hexadecimal string is "ff".

Common mistake example:

julia> hex(12.5)
ERROR: MethodError: no method matching hex(::Float64)

In this example, the hex function is called with a floating-point number, which is not a valid argument type. The hex function only works with integer arguments. Make sure to pass an integer to the hex function to avoid such errors.

See Also

base, big, bytes2hex, cconvert, complex, convert, dec, hex, hex2bytes, hex2num, oct, oftype, parse, promote, signed, unsafe_convert, unsigned, widen,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field
Details

Checking you are not a robot: