On Fri, Jan 20, 2012 at 03:14:21PM -0500, Sam Steingold wrote:
> On Fri, Jan 20, 2012 at 14:05, Sarah Goslee <[email protected]> wrote:
> >> then I need to convert each 6/8 character string into an integer base 36
> >> or 64 (depending on the field) - how?
> >
> > base 36?
>
> 10 decimal digits + 26 english characters = 36.
> ThusThisLongWordWithLettersAndDigitsFrom0to9isAnIntegerBase36
> (case insensitive).
> So, how do I convert the above long word to a bignum?
Hi.
Try the following.
x <- tolower("ThusThisLongWordWithLettersAndDigitsFrom0to9isAnIntegerBase36")
x <- strsplit(x, "")[[1]]
digits <- 0:35
names(digits) <- c(0:9, letters)
y <- digits[x]
# solution using gmp package
library(gmp)
b <- as.bigz(36)
sum(y * b^(length(y):1 - 1))
[1]
"70455190722800243410669999246294410591724807773749367607882253153084991978813070206061584038994
# solution using Rmpfr package
library(Rmpfr)
b <- mpfr(36, precBits=500)
sum(y * b^(length(y):1 - 1))
[1]
70455190722800243410669999246294410591724807773749367607882253153084991978813070206061584038994
>actually, my numbers will fit into int64, no bignum support is necessary.
The default R numeric data type is double precision,
which represents integers up to 53 bits, so the
largest exactly representable integer is 2^53.
The integer type is 32 bits.
Hope this helps.
Petr Savicky.
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.