Created
May 21, 2018 07:29
-
-
Save stackdumper/1163a41d95e9713db72fbbf7e312d343 to your computer and use it in GitHub Desktop.
hex2dec
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const hex = process.argv[2]; | |
const getInt = char => | |
({ | |
A: '10', | |
B: '11', | |
C: '12', | |
D: '13', | |
E: '14', | |
F: '15' | |
}[char.toUpperCase()] || char); | |
const dec = hex | |
.split('') | |
.reverse() | |
.reduce((acc, char, i) => { | |
return acc + getInt(hex[i]) * Math.pow(16, hex.length - i - 1); | |
}, 0); | |
console.log(dec); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment