MCPcopy Index your code
hub / github.com/TheAlgorithms/JavaScript / hexLookup

Function hexLookup

Conversions/BinaryToHex.js:6–45  ·  view source on GitHub ↗
(bin)

Source from the content-addressed store, hash-verified

4}
5
6const hexLookup = (bin) => {
7 let binary = bin
8 if (binary.length < 4) {
9 binary = pad(binary, 4)
10 }
11 switch (binary) {
12 case '0000':
13 return '0'
14 case '0001':
15 return '1'
16 case '0010':
17 return '2'
18 case '0011':
19 return '3'
20 case '0100':
21 return '4'
22 case '0101':
23 return '5'
24 case '0110':
25 return '6'
26 case '0111':
27 return '7'
28 case '1000':
29 return '8'
30 case '1001':
31 return '9'
32 case '1010':
33 return 'A'
34 case '1011':
35 return 'B'
36 case '1100':
37 return 'C'
38 case '1101':
39 return 'D'
40 case '1110':
41 return 'E'
42 case '1111':
43 return 'F'
44 }
45}
46const binaryToHex = (binaryString) => {
47 /*
48 Function for converting Binary to Hex

Callers 1

binaryToHexFunction · 0.85

Calls 1

padFunction · 0.70

Tested by

no test coverage detected