Skip to content

Instantly share code, notes, and snippets.

@johnbaums
Last active February 6, 2019 04:29
Show Gist options
  • Save johnbaums/e883538364d7520631875792dcf451a8 to your computer and use it in GitHub Desktop.
Save johnbaums/e883538364d7520631875792dcf451a8 to your computer and use it in GitHub Desktop.
Convert a hexadecimal string representation to character
hexToChar <- function(x) {
x <- sub('^0x', '', x)
sapply(x, function(y) {
h <- sapply(seq(1, nchar(y), by=2), function(i) substr(y, i, i+1))
rawToChar(as.raw(strtoi(h, 16L)))
})
}
charToHex <- function(x, prepend0x=TRUE) {
sapply(x, function(y) {
y <- paste(charToRaw(y), collapse='')
if(prepend0x) paste0('0x', y) else y
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment