Skip to content

Instantly share code, notes, and snippets.

@wkei
Last active April 13, 2022 04:02
Show Gist options
  • Save wkei/0f5e38cb9ff8c05cf443217a138c7a39 to your computer and use it in GitHub Desktop.
Save wkei/0f5e38cb9ff8c05cf443217a138c7a39 to your computer and use it in GitHub Desktop.
function intToBase16(num) {
if (num === 0) return '0'
const digits = Array.from(new Array(16), (_, i) => i < 10 ? i : String.fromCharCode(65 + i - 10))
let base16 = ''
while (num !== 0) {
base16 = digits[num % 16] + base16
num = Math.floor(num / 16)
}
return base16
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment