Re: [R] Converting Decimal numbers into Binary

2019-12-27 Thread Paul Bernal
Thank you Richard. Best regards, Paul El vie., 27 de diciembre de 2019 4:27 p. m., Richard O'Keefe < rao...@gmail.com> escribió: > The specific problem you are trying to solve is so constrained that > you do not need a > general purpose method. > You start with a string that contains characters

Re: [R] Converting Decimal numbers into Binary

2019-12-27 Thread Paul Bernal
Thank you very much Rui. Best regards! El vie., 27 de diciembre de 2019 4:22 p. m., Rui Barradas < ruipbarra...@sapo.pt> escribió: > Hello, > > You forgot to cc the list, I'm replying all to have a complete thread so > that others now and in the future can search similar problems they might > en

Re: [R] Converting Decimal numbers into Binary

2019-12-27 Thread Richard O'Keefe
The specific problem you are trying to solve is so constrained that you do not need a general purpose method. You start with a string that contains characters drawn from a *subset* of ASCII with at most 64 elements. Accordingly, all you need is a table mapping characters to 6-character strings. ta

Re: [R] Converting Decimal numbers into Binary

2019-12-27 Thread Rui Barradas
Hello, You forgot to cc the list, I'm replying all to have a complete thread so that others now and in the future can search similar problems they might encounter. The following function bin2dec works as expected. bin2dec <- function(x){ s <- strsplit(x, "") s <- lapply(s, function(x){

Re: [R] Converting Decimal numbers into Binary

2019-12-27 Thread Rui Barradas
Hello, Your code and the answers provided, specially Marc's, led me to utf8ToBin <- function(x, out = c("ascii", "dec", "bin")){ out <- match.arg(out) ascii_datformat <- utf8ToInt(x) Base <- ascii_datformat - 48 Base <- ifelse(Base > 40, Base - 8, Base) Bin <- R.utils::intToBin(Base)

Re: [R] Converting Decimal numbers into Binary

2019-12-27 Thread William Michels via R-help
Hi Paul, Since you start from strings, it's not clear to me where ASCII enters the picture. If you really need ASCII, you can use the charToInt() function in the "R.oo" package. Also there's the AsciiToInt() function in the "sfsmisc" package. If you just want to use R's native as.numeric() conver

Re: [R] Converting Decimal numbers into Binary

2019-12-27 Thread Richard M. Heiberger
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 wrote: > > Dear friends, > > Hope you are all doing well. I need to find a way to conve

Re: [R] Converting Decimal numbers into Binary

2019-12-27 Thread Paul Bernal
Dear Jeff, Hope you are doing great. The link I provide below has the results I am expecting. I am doing a test, trying to convert this string: "133m@ogP00PD ;88MD5MTDww@2D7k" into ascii numbers, then to decimal, and ultimately, into binary. I am trying to recreate the results obtained in the link

Re: [R] Converting Decimal numbers into Binary

2019-12-27 Thread Jeff Newmiller
Your question is incomplete... what do you expect the result to be? Perhaps [1] is relevant? [1] https://stackoverflow.com/questions/52298995/r-binary-decimal-conversion-confusion-ais-data On December 27, 2019 7:42:36 AM PST, Paul Bernal wrote: >Dear friends, > >Hope you are all doing well. I

Re: [R] Converting Decimal numbers into Binary

2019-12-27 Thread Marc Schwartz via R-help
> On Dec 27, 2019, at 10:42 AM, Paul Bernal 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 tro