Files
common/packages/util/src/hex/alphabet.ts
T
2022-01-01 09:26:11 +02:00

28 lines
668 B
TypeScript

// Copyright 2017-2022 @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 << 8) | j;
U16_TO_HEX[n] = hex;
HEX_TO_U16[hex] = n;
}
}
export { HEX_TO_U16, HEX_TO_U8, U16_TO_HEX, U8_TO_HEX };