Created
July 9, 2022 12:45
-
-
Save UniBreakfast/03bc0f3ba91ea6cdd7ce7bb984da3fb9 to your computer and use it in GitHub Desktop.
This file contains 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
function decToBin(int) { | |
let bin = '' | |
while (int) { | |
const digit = int % 2 | |
bin = digit + bin | |
int -= digit | |
int /= 2 | |
} | |
return bin | |
} | |
function decToOct(int) { | |
let octal = '' | |
while (int) { | |
const digit = int % 8 | |
octal = digit + octal | |
int -= digit | |
int /= 8 | |
} | |
return octal | |
} | |
function decToHex(int) { | |
const digits = '0123456789abcdef' | |
let hex = '' | |
while (int) { | |
const digit = int % 16 | |
hex = digits[digit] + hex | |
int -= digit | |
int /= 16 | |
} | |
return hex | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment