# How to convert a string to UInt8?

**URL:** <https://discourse.julialang.org/t/how-to-convert-a-string-to-uint8/65811>\
**Category:** General Usage\
**Created:** [August 4, 2021, 1:37pm UTC](https://discourse.julialang.org/t/how-to-convert-a-string-to-uint8/65811 "2021-08-04T13:37:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bardo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bardo/32/21601_2.png) [@Bardo](https://discourse.julialang.org/u/Bardo)\
**Post date:** [August 4, 2021, 1:37pm UTC](https://discourse.julialang.org/t/how-to-convert-a-string-to-uint8/65811/1 "2021-08-04T13:37:40Z")

</div>

This does not work:

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

```

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [August 4, 2021, 1:40pm UTC](https://discourse.julialang.org/t/how-to-convert-a-string-to-uint8/65811/2 "2021-08-04T13:40:05Z")

</div>

Try `codeunits`.

---

<div class="post-metadata">

**Author:** ![Impressium](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/impressium/32/19575_2.png) [@Impressium](https://discourse.julialang.org/u/Impressium)\
**Post date:** [August 4, 2021, 1:41pm UTC](https://discourse.julialang.org/t/how-to-convert-a-string-to-uint8/65811/3 "2021-08-04T13:41:35Z")

</div>

I did something like that and used `IOBuffer` and `write`.

```julia
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 🙂

---

<div class="post-metadata">

**Author:** ![Bardo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bardo/32/21601_2.png) [@Bardo](https://discourse.julialang.org/u/Bardo)\
**Post date:** [August 4, 2021, 1:48pm UTC](https://discourse.julialang.org/t/how-to-convert-a-string-to-uint8/65811/4 "2021-08-04T13:48:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [August 4, 2021, 1:57pm UTC](https://discourse.julialang.org/t/how-to-convert-a-string-to-uint8/65811/5 "2021-08-04T13:57:43Z")

</div>

What about reinterpret?

---

<div class="post-metadata">

**Author:** ![Bardo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bardo/32/21601_2.png) [@Bardo](https://discourse.julialang.org/u/Bardo)\
**Post date:** [August 4, 2021, 1:59pm UTC](https://discourse.julialang.org/t/how-to-convert-a-string-to-uint8/65811/6 "2021-08-04T13:59:45Z")

</div>

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