1
1
mirror of https://github.com/Fabio286/antares.git synced 2025-06-05 21:59:22 +02:00

refactor: common to ts

This commit is contained in:
2022-05-10 12:57:25 +02:00
parent d1bfa282c3
commit cc5910b88f
27 changed files with 151 additions and 69 deletions

View File

@@ -0,0 +1,34 @@
const lookup = {
0: '0000',
1: '0001',
2: '0010',
3: '0011',
4: '0100',
5: '0101',
6: '0110',
7: '0111',
8: '1000',
9: '1001',
a: '1010',
b: '1011',
c: '1100',
d: '1101',
e: '1110',
f: '1111',
A: '1010',
B: '1011',
C: '1100',
D: '1101',
E: '1110',
F: '1111'
} as const;
type HexChar = keyof typeof lookup
export default function hexToBinary (hex: HexChar[]) {
let binary = '';
for (let i = 0; i < hex.length; i++)
binary += lookup[hex[i]];
return binary;
}