Skip to content

Commit 32f1e33

Browse files
merge: Added Hex to Binary conversion (TheAlgorithms#805)
* Added Hex to Binary conversion * Update Conversions/HexToBinary.js Co-authored-by: Rak Laptudirm <[email protected]> * Update Conversions/HexToBinary.js Co-authored-by: Rak Laptudirm <[email protected]> * Update Conversions/HexToBinary.js Co-authored-by: Rak Laptudirm <[email protected]> * Update Conversions/HexToBinary.js Co-authored-by: Rak Laptudirm <[email protected]> * Fix errors * fix: typo Co-authored-by: Rak Laptudirm <[email protected]>
1 parent d19108b commit 32f1e33

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

Conversions/HexToBinary.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,14 @@ const binLookup = (c) => {
2121
}
2222
const hexToBinary = (hexString) => {
2323
/*
24-
Function for convertung Hex to Binary
24+
Function for converting Hex to Binary
2525
2626
1. We convert every hexadecimal bit to 4 binary bits
2727
2. Conversion goes by searching in the lookup table
2828
2929
*/
30-
31-
let result = ''
32-
hexString = hexString.split('')
33-
hexString.forEach(c => { result += binLookup(c) })
34-
return result
30+
const hexLexemes = hexString.split('')
31+
return hexLexemes.map(lexeme => binLookup(lexeme)).join('')
3532
}
3633

3734
export default hexToBinary

0 commit comments

Comments
 (0)