nupp.codec.hex

Bytes as hexadecimal.

const hex = require("nupp.codec.hex")

print(hex.encode("Nu"))          -- 4e75
print(hex.decode("4E75"))        -- Nu

encode writes lowercase; decode reads either case, and wants nothing around the digits -- no whitespace, no 0x.

Module contents

Functions

FunctionKindDescription
decodefunctionDecodes hexadecimal without whitespace or a prefix.
encodefunctionEncodes raw bytes as lowercase hexadecimal.

Functions#

decodefunction#

function decode(text: string): string?, string?

Decodes hexadecimal without whitespace or a prefix.

Arguments

NameTypeDescription
textstring

Returns

TypeDescription
string?

raw bytes, or nil and a reason

string?

encodefunction#

function encode(bytes: string): string

Encodes raw bytes as lowercase hexadecimal.

Arguments

NameTypeDescription
bytesstring

Returns

TypeDescription
string