How to convert characters to ASCii code or the corresponding binary string. "R"

I need to translate a character string, such as "Hello" , into a string of numbers, which is an ASCII numeric code.

Example: 0 -> 48; a -> 97 0 -> 48; a -> 97 etc.

Does anyone know the R function for this? Hope a function or code snippet converts "Hello" to a number string, for example

 c(72, 101, 108, 108, 111) 
+6
source share
1 answer

I think you mean utf8ToInt , see R docs http://www.inside-r.org/r-doc/base/utf8ToInt

 utf8ToInt("Hello") # [1] 72 101 108 108 111 

Or, if you need to match letters with their codes:

 sapply(strsplit("Hello", NULL)[[1L]], utf8ToInt) # H ello # 72 101 108 108 111 
+10
source

All Articles