Skip to content

Instantly share code, notes, and snippets.

@UniBreakfast
Created July 9, 2022 12:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save UniBreakfast/03bc0f3ba91ea6cdd7ce7bb984da3fb9 to your computer and use it in GitHub Desktop.
Save UniBreakfast/03bc0f3ba91ea6cdd7ce7bb984da3fb9 to your computer and use it in GitHub Desktop.
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