UNPKG

597 BJavaScriptView Raw
1// Copyright 2017-2022 @polkadot/util authors & contributors
2// SPDX-License-Identifier: Apache-2.0
3const U8_TO_HEX = new Array(256);
4const U16_TO_HEX = new Array(256 * 256);
5const HEX_TO_U8 = {};
6const HEX_TO_U16 = {};
7
8for (let n = 0; n < 256; n++) {
9 const hex = n.toString(16).padStart(2, '0');
10 U8_TO_HEX[n] = hex;
11 HEX_TO_U8[hex] = n;
12}
13
14for (let i = 0; i < 256; i++) {
15 for (let j = 0; j < 256; j++) {
16 const hex = U8_TO_HEX[i] + U8_TO_HEX[j];
17 const n = i << 8 | j;
18 U16_TO_HEX[n] = hex;
19 HEX_TO_U16[hex] = n;
20 }
21}
22
23export { HEX_TO_U16, HEX_TO_U8, U16_TO_HEX, U8_TO_HEX };
\No newline at end of file