.toBase(base)
Description
Parameters
Usage On Numbers
num = 255
log num.toBase(10, 16)
// "ff"
// converts to hexadecimal
log num.toBase(10, 2)
// "11111111"
// converts to binary
log num.toBase(10, 8)
// "377"
// converts to octal
num = 15
log num.toBase(10, 16)
// "f"
// single digit hex number
// Can be used with any base from 2 to 36
num = 42
log num.toBase(10, 36)
// "16"
// maximum base using 0-9 and a-z
// Converting from an abnormal base to decimal also works.
hex = "ff"
log hex.toBase(16, 10)
// "255"
// Negative numbers are supported
num = -255
log num.toBase(10, 16)
// "-ff"Last updated