mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-06 01:18:23 +08:00
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:
@ -21,17 +21,14 @@ const binLookup = (c) => {
|
|||||||
}
|
}
|
||||||
const hexToBinary = (hexString) => {
|
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
|
1. We convert every hexadecimal bit to 4 binary bits
|
||||||
2. Conversion goes by searching in the lookup table
|
2. Conversion goes by searching in the lookup table
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
const hexLexemes = hexString.split('')
|
||||||
let result = ''
|
return hexLexemes.map(lexeme => binLookup(lexeme)).join('')
|
||||||
hexString = hexString.split('')
|
|
||||||
hexString.forEach(c => { result += binLookup(c) })
|
|
||||||
return result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default hexToBinary
|
export default hexToBinary
|
||||||
|
Reference in New Issue
Block a user