Skip to content

Commit

Permalink
bytes2hex: reimplement efficiently (close #14341)
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanKarpinski committed Dec 15, 2015
1 parent 10e8b52 commit 97443cd
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion base/strings/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,12 @@ function hex2bytes(s::AbstractString)
return a
end

bytes2hex(arr::Vector{UInt8}) = join([hex(i,2) for i in arr])
function bytes2hex(a::AbstractArray{UInt8})
b = Vector{UInt8}(2*length(a))
i = 0
for x in a
b[i += 1] = hex_chars[1 + x >> 4]
b[i += 1] = hex_chars[1 + x & 0xf]
end
return ASCIIString(b)
end

0 comments on commit 97443cd

Please sign in to comment.