Last active
May 21, 2018 07:29
-
-
Save stackdumper/ccf6824099371340e739504aa7504125 to your computer and use it in GitHub Desktop.
dec2hex
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
let dec = process.argv[2]; | |
let result = ''; | |
const getChar = char => | |
({ | |
'10': 'A', | |
'11': 'B', | |
'12': 'C', | |
'13': 'D', | |
'14': 'E', | |
'15': 'F' | |
}[char] || char); | |
do { | |
const float = dec / 16; | |
const int = (dec = Math.floor(float)); | |
const remainder = (float - int) * 16; | |
result = getChar(remainder) + result; | |
} while (dec !== 0); | |
console.log(result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment