How to convert a string to UInt8?

This does not work:

reinterpret(UInt8, "Ab")
UInt8.("Ab")

Try codeunits.

4 Likes

I did something like that and used IOBuffer and write.

julia> io = IOBuffer()
IOBuffer(data=UInt8[...], readable=true, writable=true, seekable=true, append=false, size=0, maxsize=Inf, ptr=1, mark=-1)

julia> write(io, "Hello World!")
12

julia> uints = take!(io)
12-element Vector{UInt8}:
 0x48
 0x65
 0x6c
 0x6c
 0x6f
 0x20
 0x57
 0x6f
 0x72
 0x6c
 0x64
 0x21

Don’t know if that’s the right way :slight_smile:

1 Like

Thanks to you both!
I am writing a yet another de/serializer for Matlab<->Julia, also to learn Julia.
Feeling there is no single convert-to-UInt8 command you can throw whatever at.
Will post my findings in another thread.

What about reinterpret?

Pls see above my failed trial. How would you do it?