Created
October 24, 2012 12:24
-
-
Save nanxstats/3945794 to your computer and use it in GitHub Desktop.
R function to convert a string into a vector of its ASCII numbers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ord <- function(x) { | |
s <- x[1] | |
intbits <- .Machine$sizeof.long * 4 | |
bits <- raw(nchar(s) * intbits) | |
r <- charToRaw(x) | |
idx <- if (.Platform$endian == "little") 1:8 else 25:32 | |
for (i in 1:nchar(s)) { | |
bits[idx + ((i - 1) * intbits)] <- rawToBits(r[i]) | |
} | |
packBits(bits, 'integer') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment