Skip to content

Commit 97443cd

Browse files
bytes2hex: reimplement efficiently (close #14341)
1 parent 10e8b52 commit 97443cd

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

base/strings/util.jl

+9-1
Original file line numberDiff line numberDiff line change
@@ -234,4 +234,12 @@ function hex2bytes(s::AbstractString)
234234
return a
235235
end
236236

237-
bytes2hex(arr::Vector{UInt8}) = join([hex(i,2) for i in arr])
237+
function bytes2hex(a::AbstractArray{UInt8})
238+
b = Vector{UInt8}(2*length(a))
239+
i = 0
240+
for x in a
241+
b[i += 1] = hex_chars[1 + x >> 4]
242+
b[i += 1] = hex_chars[1 + x & 0xf]
243+
end
244+
return ASCIIString(b)
245+
end

0 commit comments

Comments
 (0)