A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/fromHex below:

Uint8Array.fromHex() - JavaScript | MDN

Uint8Array.fromHex()

Limited availability

The Uint8Array.fromHex() static method creates a new Uint8Array object from a hexadecimal string.

This method parses the string into a byte array. To convert the string into a single number, use the parseInt() function with radix set to 16 instead.

Syntax
Uint8Array.fromHex(string)
Parameters
string

A hexadecimal string encoding bytes to convert to a Uint8Array. The string must:

Return value

A new Uint8Array object containing the decoded bytes from the hexadecimal string.

Exceptions
SyntaxError

Thrown if the input string contains characters outside the hex alphabet, or its length is odd.

TypeError

Thrown if the input string is not a string.

Examples Decoding a hexadecimal string

This example decodes a hexadecimal string into a Uint8Array.

const hexString = "cafed00d";
const bytes = Uint8Array.fromHex(hexString);
console.log(bytes); // Uint8Array [ 202, 254, 208, 13 ]

Uppercase characters are also supported:

const hexString = "CAFEd00d";
const bytes = Uint8Array.fromHex(hexString);
console.log(bytes); // Uint8Array [ 202, 254, 208, 13 ]
Specifications Browser compatibility See also

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4