Encoding
This document describes the Encoding library available in the JavaScript environment for app services.
Table of content
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 data | An Uint8Array containing the data to convert. |
Return value
sting | The 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 hexstring | A hexadecimal string. |
Return value
Uint8Array | The 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 data | An Uint8Array containing binary string data. |
Return value
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 data | A string to convert. |
Return value
Uint8Array | The 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])