raw2hex: Convert raw vector to string hex representation

Description Usage Arguments Details Value Author(s) Examples

View source: R/tools.R

Description

raw2hex convers a raw vector into hexadecimal representation

Usage

1
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(s)

Simon Urbanek

Examples

1
2
3
4
5
6
7
8
9
raw2hex(PKI.digest(raw(), "SHA1"), "")
raw2hex(PKI.digest(raw(), "MD5"), ":")

## 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, " "))
system.time(h2 <- paste(raw2hex(x), collapse=" "))
stopifnot(identical(h1, h2))

Example output

Loading required package: base64enc
[1] "da39a3ee5e6b4b0d3255bfef95601890afd80709"
[1] "d4:1d:8c:d9:8f:00:b2:04:e9:80:09:98:ec:f8:42:7e"
   user  system elapsed 
  0.002   0.000   0.001 
   user  system elapsed 
  0.016   0.000   0.016 

PKI documentation built on Sept. 16, 2017, 5:03 p.m.

Related to raw2hex in PKI...