# (a) single numeric input:
dec2base(3) # base = 2
dec2base(8, base = 2)
dec2base(8, base = 3)
dec2base(8, base = 7)
dec2base(100, base = 5)
dec2base(100, base = 10)
dec2base(100, base = 15)
dec2base(14, base = 14)
dec2base(15, base = 15)
dec2base(16, base = 16)
dec2base(15, base = 16)
dec2base(31, base = 16)
dec2base(47, base = 16)
# (b) single string input:
dec2base("7", base = 2)
dec2base("8", base = 3)
# Extreme values:
dec2base(base2dec(rep("1", 32))) # 32 x "1"
dec2base(base2dec(c("1", rep("0", 32)))) # 2^32
dec2base(base2dec(rep("1", 33))) # 33 x "1"
dec2base(base2dec(c("1", rep("0", 33)))) # 2^33
# Non-standard inputs:
dec2base(" ") # only spaces: NA
dec2base("?") # no decimal digits: NA
dec2base(" 10 ", 2) # remove leading and trailing spaces
dec2base("-10", 2) # handle negative inputs (in character strings)
dec2base(" -- 10", 2) # handle multiple negations
dec2base("xy -10 ", 2) # ignore non-decimal digit prefixes
# Note:
base2dec(dec2base(012340, base = 9), base = 9)
dec2base(base2dec(043210, base = 11), base = 11)
Run the code above in your browser using DataLab