A RetroSearch Logo

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

Search Query:

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

Uint8Array.fromHex() - JavaScript | MDN

Uint8Array.fromHex()

Limited availability

Uint8Array.fromHex() は静的メソッドで、新しい Uint8Array オブジェクトを 16 進文字列から作成します。

このメソッドは、文字列をバイト配列に解釈します。文字列を単一の数値に変換するには、代わりに parseInt() 関数を、 radix を 16 に設定して使用してください。

構文
Uint8Array.fromHex(string)
引数
string

Uint8Array に変換するバイト列をエンコードした 16 進文字列。文字列は次の条件を満たす必要があります。

返値

16 進文字列からデコードされたバイトが含まれている新しい Uint8Array オブジェクト。

例外
SyntaxError

入力文字列に 16 進文字以外の文字が含まれているか、その長さが奇数の場合に発生します。

TypeError

入力文字列が文字列でない場合に発生します。

例 16 進文字列のデコード

この例では、16 進文字列を Uint8Array にデコードしています。

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

大文字も対応しています。

const hexString = "CAFEd00d";
const bytes = Uint8Array.fromHex(hexString);
console.log(bytes); // Uint8Array [ 202, 254, 208, 13 ]
仕様書 ブラウザーの互換性 関連情報

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