Skip to content

infinity.hex

Provides hexadecimal-encoding and decoding functionality.

Module: infinity.encoding

Functions:

Example:

infinity.loadModule('infinity.encoding');

let encodedData = infinity.hex.encode('AUO_ÄÜÖ ß-"+&,?.<=>');
console.debug(encodedData);
//41554F5FC384C39CC39620C39F2D222B262C3F2E3C3D3E

let decodedData = infinity.hex.decode(encodedData);
console.debug(decodedData);
//AUO_ÄÜÖ ß-"+&,?.<=>

Functions

decode()

Decodes the given hexadecimal string (upper- or lowercase, two hex digits per byte, no separators) to bytes and returns them as a string, decoded with the given encoding. The input is not validated: a trailing single digit is ignored, and conversion stops at the first invalid character (the remaining bytes are zero). Returns an empty string if value is empty.

Signature:

decode( value: string, encoding?: infinity.encoding ): string

Parameters:

  • value: string

    The string to decode.

  • encoding: infinity.encoding, optional

    The encoding of the decoded bytes. If omitted, the bytes are decoded as UTF-8, or as Windows-1252 if they are not valid UTF-8.

Return type: string

Example:

infinity.loadModule('infinity.encoding');
let decodedData = infinity.hex.decode(encodedData);

encode()

Converts the given string to bytes using the given encoding and returns them as uppercase hexadecimal codes (two characters per byte). Returns an empty string if value is empty.

Signature:

encode( value: string, encoding?: infinity.encoding ): string

Parameters:

  • value: string

    The string to encode.

  • encoding: infinity.encoding, optional

    The encoding used to convert the string to bytes. Defaults to infinity.encoding.utf8.

Return type: string

Example:

infinity.loadModule('infinity.encoding');
let encodedData = infinity.hex.encode(dataToEncode);