import { assertEquals as assertEq } from "jsr:@std/assert"
const
my_binary_code = [1, 2, 3, 125, 126, 127, 192, 225, 255],
my_custom_config: Partial<HexStringReprConfig> = {
sep: ",",
trailingSep: true,
bra: "<",
ket: ">",
}
const my_binary_code_repr = hexStringOfArray(my_binary_code, my_custom_config)
assertEq(my_binary_code_repr, "<0x01,0x02,0x03,0x7D,0x7E,0x7F,0xC0,0xE1,0xFF,>")
convert an array of integer numbers to hex-string, for the sake of easing representation, or for visual purposes.
to customize the apearance of the hex-string, or to use a different radix, use the HexStringReprConfig interface to change the default
options
.you must make sure that every element of your array
arr
is non-negative, in addition to being less thanoptions.radix ** 2
. since the defaultoptions.radix === 16
, each of your number must be smaller than256
on the default config.to invert the operation of this function (i.e. parse an array of integers from a string), use the hexStringToArray function with the same config
options
.