Last data update: 2014.03.03

R: Convert raw vector to string hex representation
raw2hexR Documentation

Convert raw vector to string hex representation

Description

raw2hex convers a raw vector into hexadecimal representation

Usage

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

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

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(PKI)
Loading required package: base64enc
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/PKI/raw2hex.Rd_%03d_medium.png", width=480, height=480)
> ### Name: raw2hex
> ### Title: Convert raw vector to string hex representation
> ### Aliases: raw2hex
> ### Keywords: manip
> 
> ### ** 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.000   0.000   0.001 
> system.time(h2 <- paste(raw2hex(x), collapse=" "))
   user  system elapsed 
  0.012   0.000   0.012 
> stopifnot(identical(h1, h2))
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>