Encoding

This document describes the Encoding library available in the JavaScript environment for app services.

Table of content

Object Encoding
Functions binToHex
hexToBin
binToString
stringToBin

Encoding

The Encoding object provides functions for converting between different data types and encodings.

binToHex
Converts from binary data contained in an Uint8Array to a hex string.

Parameters

Uint8Array dataAn Uint8Array containing the data to convert.

Return value

stingThe hex string representation of data.
var bin = new Uint8Array([0x00, 0x01, 0x02]);
var hexstring = Encoding.binToHex(bin);
// hexstring contains "000102"
hexToBin
Converts a hex string to an Uint8Array containing binary data.

Parameters

string hexstringA hexadecimal string.

Return value

Uint8ArrayThe binary representation of hexstring.

Remarks

null is converted to an Uint8Array of length 0.

var hexstring = "000102";
var bin = Encoding.hexToBin(hexstring);
// bin is equivalent to new Uint8Array([0x00, 0x01, 0x02])
binToString
Converts a Uint8Array to a string.

Parameters

Uint8Array dataAn Uint8Array containing binary string data.

Return value

stingThe string.

Remarks

null is converted to an empty string.

var bin = new Uint8Array([0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65]);
var string = Encoding.binToString(bin);
// hexstring contains "example"
stringToBin
Converts a string to a Uint8Array.

Parameters

string dataA string to convert.

Return value

Uint8ArrayThe binary representation of data.

Remarks

null is converted to an Uint8Array of length 0.

var string = "example";
var bin = Encoding.stringToBin(string);
// bin is equivalent to new Uint8Array([0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65])