merge: Added Hex to Binary conversion (#805)

* Added Hex to Binary conversion

* Update Conversions/HexToBinary.js

Co-authored-by: Rak Laptudirm <raklaptudirm@gmail.com>

* Update Conversions/HexToBinary.js

Co-authored-by: Rak Laptudirm <raklaptudirm@gmail.com>

* Update Conversions/HexToBinary.js

Co-authored-by: Rak Laptudirm <raklaptudirm@gmail.com>

* Update Conversions/HexToBinary.js

Co-authored-by: Rak Laptudirm <raklaptudirm@gmail.com>

* Fix errors

* fix: typo

Co-authored-by: Rak Laptudirm <raklaptudirm@gmail.com>
This commit is contained in:
Dhana D
2021-10-24 15:56:56 +07:00
committed by GitHub
parent d19108b481
commit 32f1e3351c

View File

@ -21,17 +21,14 @@ const binLookup = (c) => {
}
const hexToBinary = (hexString) => {
/*
Function for convertung Hex to Binary
Function for converting Hex to Binary
1. We convert every hexadecimal bit to 4 binary bits
2. Conversion goes by searching in the lookup table
*/
let result = ''
hexString = hexString.split('')
hexString.forEach(c => { result += binLookup(c) })
return result
const hexLexemes = hexString.split('')
return hexLexemes.map(lexeme => binLookup(lexeme)).join('')
}
export default hexToBinary