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

Function hexToBinary

Conversions/HexToBinary.js:21–37  ·  view source on GitHub ↗
(hexString)

Source from the content-addressed store, hash-verified

19 })[key.toLowerCase()] // select the binary number by valid hex key with the help javascript object
20
21const hexToBinary = (hexString) => {
22 if (typeof hexString !== 'string') {
23 throw new TypeError('Argument is not a string type')
24 }
25
26 if (/[^\da-f]/gi.test(hexString)) {
27 throw new Error('Argument is not a valid HEX code!')
28 }
29 /*
30 Function for converting Hex to Binary
31
32 1. We convert every hexadecimal bit to 4 binary bits
33 2. Conversion goes by searching in the lookup table
34 */
35
36 return hexString.replace(/[0-9a-f]/gi, (lexeme) => binLookup(lexeme))
37}
38
39export default hexToBinary

Callers 1

Calls 1

binLookupFunction · 0.85

Tested by

no test coverage detected