[R] X-Priority: 3 (Normal)
oehl_list@gmx.de
oehl_list at gmx.de
Tue Oct 15 17:13:39 CEST 2002
# you need to distinguish datatypes 'character' and 'numeric'
bindec <- function(
b # a CHARACTER representing a binary number
){
as.i <- as.integer(unlist(strsplit(b,"")))
print(as.i)
fl <- 2^(floor(round(log10(as.numeric(b)),10)):0) # convert b to numeric
print(fl)
dec <- sum(as.i * fl)
dec
}
> bindec("100000")
[1] 1 0 0 0 0 0
[1] 32 16 8 4 2 1
[1] 32
# Best
# Jens Oehlschlägel
--
+++ GMX - Mail, Messaging & more http://www.gmx.net +++
NEU: Mit GMX ins Internet. Rund um die Uhr für 1 ct/ Min. surfen!
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list