raw2hex.Rd
raw2hex
convers a raw vector into hexadecimal representation
raw2hex(what, sep, upper = FALSE)
raw vector
optional separator string
logical, if TRUE
then upper case letters are used,
otherwise any letters will be lower case.
If sep
is omitted or NULL
then the resulting character
vector will have as many elements as the raw vector. Otherwise the
elements are concatenated using the specified separator into one
character string. This is much more efficient than using
paste(raw2hex(x), collapse=sep)
, but has the same effect.
Character vector with the hexadecimal representation of the raw vector.
raw2hex(PKI.digest(raw(), "SHA1"), "")
#> [1] "da39a3ee5e6b4b0d3255bfef95601890afd80709"
raw2hex(PKI.digest(raw(), "MD5"), ":")
#> [1] "d4:1d:8c:d9:8f:00:b2:04:e9:80:09:98:ec:f8:42:7e"
## this is jsut a performance comparison and a test that
## raw2hex can handle long strings
x <- as.raw(runif(1e5) * 255.9)
system.time(h1 <- raw2hex(x, " "))
#> user system elapsed
#> 0.001 0.000 0.000
system.time(h2 <- paste(raw2hex(x), collapse=" "))
#> user system elapsed
#> 0.012 0.000 0.012
stopifnot(identical(h1, h2))