# (a) single string input:
base2dec("11") # default base = 2
base2dec("0101")
base2dec("1010")
base2dec("11", base = 3)
base2dec("11", base = 5)
base2dec("11", base = 10)
base2dec("11", base = 12)
base2dec("11", base = 14)
base2dec("11", base = 16)
# (b) numeric vectors as inputs:
base2dec(c(0, 1, 0))
base2dec(c(0, 1, 0), base = 3)
# (c) character vector as inputs:
base2dec(c("0", "1", "0"))
base2dec(c("0", "1", "0"), base = 3)
# (d) multi-digit vectors:
base2dec(c(1, 1))
base2dec(c(1, 1), base = 3)
# Extreme values:
base2dec(rep("1", 32)) # 32 x "1"
base2dec(c("1", rep("0", 32))) # 2^32
base2dec(rep("1", 33)) # 33 x "1"
base2dec(c("1", rep("0", 33))) # 2^33
# Non-standard inputs:
base2dec(" ", 2) # no non-spaces: NA
base2dec(" ?! ", 2) # no base digits: NA
base2dec(" 100 ", 2) # remove leading and trailing spaces
base2dec("- 100", 2) # handle negative inputs (value < 0)
base2dec("- -100", 2) # handle double negations
base2dec("---100", 2) # handle multiple negations
# Special cases:
base2dec(NA)
base2dec(0)
base2dec(c(3, 3), base = 3) # Note message!
# Note:
base2dec(dec2base(012340, base = 9), base = 9)
dec2base(base2dec(043210, base = 11), base = 11)
Run the code above in your browser using DataLab