@tempots/std

toHex() function

Converts a number to its hexadecimal representation.

Signature:

toHex: (num: number, length?: number) => string

Parameters

Parameter

Type

Description

num

number

The number to convert.

length

number

(Optional) The desired length of the hexadecimal string. Defaults to 0.

Returns: string

The hexadecimal representation of the number.

Example

toHex(255) // returns 'ff'
toHex(255, 4) // returns '00ff'
toHex(255, 8) // returns '000000ff'