Files
common/packages/util/src/hex/alphabet.ts
T
Jaco de7817e6b5 Use DataView as applicable (#1186)
* Use DataView as applicable

* .skip

* Fix hexToU8a length calc

* hello world
2021-11-15 13:01:47 +02:00

28 lines
669 B
TypeScript

// Copyright 2017-2021 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
const U8_TO_HEX = new Array<string>(256);
const U16_TO_HEX = new Array<string>(256 * 256);
const HEX_TO_U8: Record<string, number> = {};
const HEX_TO_U16: Record<string, number> = {};
for (let n = 0; n < 256; n++) {
const hex = n.toString(16).padStart(2, '0');
U8_TO_HEX[n] = hex;
HEX_TO_U8[hex] = n;
}
for (let i = 0; i < 256; i++) {
for (let j = 0; j < 256; j++) {
const hex = U8_TO_HEX[i] + U8_TO_HEX[j];
const n = (i * 256) + j;
U16_TO_HEX[n] = hex;
HEX_TO_U16[hex] = n;
}
}
export { HEX_TO_U16, HEX_TO_U8, U16_TO_HEX, U8_TO_HEX };