Hi all, is there a method for transforming 1010 into 10, i.e. a binary number into a decimal value? kind regards, Egon -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
binary to decimal number
2 messages · Egon Willighagen, Uwe Ligges
1 day later
"E.L. Willighagen" wrote:
Hi all, is there a method for transforming 1010 into 10, i.e. a binary number into a decimal value?
I don't have a clever idea right now, but the following should do the trick, if your binary number is called "b": bindec <- function(b) sum(as.integer(unlist(strsplit(b, ""))) * 2^(floor(log10(b)):0)) bindec(b) Uwe Ligges -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._