Gundala Viswanath
2008-Dec-22 09:22 UTC
[R] Convert ASCII string to Decimal in R (vice versa) was: Hex
Hi Dieter, Sorry my mistake. I wanted to convert them into Decimal (not Hexadecimal). Given this string, the desired answer follows:> ascii_str <- "ORQ>IK"79 82 81 62 73 75> ascii_str2 <- "FDC"70 68 67 - Gundala Viswanath Jakarta - Indonesia On Mon, Dec 22, 2008 at 5:49 PM, Dieter Menne <dieter.menne at menne-biomed.de> wrote:> Gundala Viswanath <gundalav <at> gmail.com> writes: > >> For example I have the following ASCII strings: >> >> > ascii_str <- "ORRRIROOQRQQOLORRRRRRQRROKK>IKFAA" >> > ascii_str2 <- "FFFFFFFFFFDDDDDDDDDDCCCCC>>>>>>>>>" >> >> Each character in the above string represent a hexadecimal value. >> I want to translate those string into an array (of size == string length) >> which contain hexadecimal conversion. >> >> as.hexmode doesn't seem to do the job. > > Trying again, simplified > > ascii_str <- "ORQ>IK" > ascii_str2 <- "FDC" > > What do you want as output in both cases? I can partially understand the second > case, but not the first. > > Dieter > > ______________________________________________ > R-help at r-project.org mailing list > 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. >
jim holtman
2008-Dec-22 09:50 UTC
[R] Convert ASCII string to Decimal in R (vice versa) was: Hex
?raw On Mon, Dec 22, 2008 at 4:22 AM, Gundala Viswanath <gundalav at gmail.com> wrote:> Hi Dieter, > > Sorry my mistake. I wanted to convert them > into Decimal (not Hexadecimal). > > Given this string, the desired answer follows: > >> ascii_str <- "ORQ>IK" > 79 82 81 62 73 75 > >> ascii_str2 <- "FDC" > 70 68 67 > > - Gundala Viswanath > Jakarta - Indonesia > > > > On Mon, Dec 22, 2008 at 5:49 PM, Dieter Menne > <dieter.menne at menne-biomed.de> wrote: >> Gundala Viswanath <gundalav <at> gmail.com> writes: >> >>> For example I have the following ASCII strings: >>> >>> > ascii_str <- "ORRRIROOQRQQOLORRRRRRQRROKK>IKFAA" >>> > ascii_str2 <- "FFFFFFFFFFDDDDDDDDDDCCCCC>>>>>>>>>" >>> >>> Each character in the above string represent a hexadecimal value. >>> I want to translate those string into an array (of size == string length) >>> which contain hexadecimal conversion. >>> >>> as.hexmode doesn't seem to do the job. >> >> Trying again, simplified >> >> ascii_str <- "ORQ>IK" >> ascii_str2 <- "FDC" >> >> What do you want as output in both cases? I can partially understand the second >> case, but not the first. >> >> Dieter >> >> ______________________________________________ >> R-help at r-project.org mailing list >> 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. >> > > ______________________________________________ > R-help at r-project.org mailing list > 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
Dieter Menne
2008-Dec-22 09:54 UTC
[R] Convert ASCII string to Decimal in R (vice versa) was: Hex
Gundala Viswanath <gundalav <at> gmail.com> writes:> Sorry my mistake. I wanted to convert them > into Decimal (not Hexadecimal). > > Given this string, the desired answer follows: > > > ascii_str <- "ORQ>IK" > 79 82 81 62 73 75 > > > ascii_str2 <- "FDC" > 70 68 67You might have a look at Henrik Bengtsson's charToInt in R.oo. And peek at the code with some nice caveats from Peter Dalgaard and Brian Ripley. Dieter
Dieter Menne
2008-Dec-22 10:01 UTC
[R] Convert ASCII string to Decimal in R (vice versa) was: Hex
Gundala Viswanath <gundalav <at> gmail.com> writes:> Sorry my mistake. I wanted to convert them > into Decimal (not Hexadecimal). > > Given this string, the desired answer follows: > > > ascii_str <- "ORQ>IK" > 79 82 81 62 73 75 > > > ascii_str2 <- "FDC" > 70 68 67 >lapply("ABCD",charToRaw)[[1]] Dieter