[R] Converting Decimal numbers into Binary

Richard M. Heiberger rmh @end|ng |rom temp|e@edu
Fri Dec 27 17:34:16 CET 2019


Use the Rmpfr  package.
it will print numbers in any base from 2  to 62
> library(Rmpfr)
> ?Rmpfr
> b15 <- mpfr(15, precBits=6)
> formatBin(b15)
[1] +0b1.11100p+3
>

On Fri, Dec 27, 2019 at 10:43 AM Paul Bernal <paulbernal07 using gmail.com> wrote:
>
> Dear friends,
>
> Hope you are all doing well. I need to find a way to convert ascii numbers
> to six digit binary numbers:
>
> I am working with this example, I converted the string to ascii, and
> finally to decimal, but I am having trouble converting the decimal numbers
> into their six digit binary representation. The code below is exactly what
> I have so far:
>
> ascii_datformat <- utf8ToInt("133m using ogP00PD;88MD5MTDww using 2D7k")
> ascii_datformat
>
> Base <- ascii_datformat - 48
>
> ifelse(Base > 40, Base-8, Base)
>
> x <- rev(intToBits(Base))
> dec2bin <- function(x) paste(as.integer(rev(intToBits(x))), collapse = "")
> dec2bin
>
> any guidance will be greatly appreciated,
>
> Best regards,
>
> Paul
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.



More information about the R-help mailing list