[R] Converting Decimal numbers into Binary

Marc Schwartz m@rc_@chw@rtz @end|ng |rom me@com
Fri Dec 27 17:11:11 CET 2019


> On Dec 27, 2019, at 10:42 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


You might look at the intToBin() function in Henrik's R.utils package on CRAN:

https://cran.r-project.org/web/packages/R.utils/index.html

Regards,

Marc Schwartz



More information about the R-help mailing list