raw2hex convers a raw vector into hexadecimal representation

raw2hex(what, sep, upper = FALSE)

Arguments

what

raw vector

sep

optional separator string

upper

logical, if TRUE then upper case letters are used, otherwise any letters will be lower case.

Details

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.

Value

Character vector with the hexadecimal representation of the raw vector.

Author

Simon Urbanek

Examples

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))