# Converting byte array to an array of another primitive type

**URL:** https://discourse.julialang.org/t/converting-byte-array-to-an-array-of-another-primitive-type/3922
**Category:** General Usage
**Created:** [May 25, 2017, 2:57pm UTC](https://discourse.julialang.org/t/converting-byte-array-to-an-array-of-another-primitive-type/3922 "2017-05-25T14:57:29Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)
#### Post date: [May 25, 2017, 2:57pm UTC](https://discourse.julialang.org/t/converting-byte-array-to-an-array-of-another-primitive-type/3922/1 "2017-05-25T14:57:29Z")

</div>

If I have a byte array generated from an array of Float64 numbers, how can I get back the array of Float64 numbers?

---

<div class="post-metadata">

### Author: ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)
#### Post date: [May 25, 2017, 3:05pm UTC](https://discourse.julialang.org/t/converting-byte-array-to-an-array-of-another-primitive-type/3922/2 "2017-05-25T15:05:56Z")

</div>

If it is generated by `reinterpret` a `Float64` array, you can `reinterpret` it back. If it’s directly generated as a `UInt8` array, you should either think about generating `Float64` array directly, or create a `Float64` array and copy the data over with `unsafe_copy!`.

---

<div class="post-metadata">

### Author: ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)
#### Post date: [May 25, 2017, 3:08pm UTC](https://discourse.julialang.org/t/converting-byte-array-to-an-array-of-another-primitive-type/3922/3 "2017-05-25T15:08:17Z")

</div>

Great `reinterpret` is what I was looking for. Thank you.

---

<div class="post-metadata">

### Author: ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)
#### Post date: [May 25, 2017, 3:09pm UTC](https://discourse.julialang.org/t/converting-byte-array-to-an-array-of-another-primitive-type/3922/4 "2017-05-25T15:09:46Z")

</div>

No you must not use `reinterpret` if the data is not generated as a `Float64` array originally.

---

<div class="post-metadata">

### Author: ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)
#### Post date: [May 25, 2017, 3:10pm UTC](https://discourse.julialang.org/t/converting-byte-array-to-an-array-of-another-primitive-type/3922/5 "2017-05-25T15:10:39Z")

</div>

Yes I know the type of the original data.

---

<div class="post-metadata">

### Author: ![ggggggggg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ggggggggg/32/265_2.png) [@ggggggggg](https://discourse.julialang.org/u/ggggggggg)
#### Post date: [May 25, 2017, 3:12pm UTC](https://discourse.julialang.org/t/converting-byte-array-to-an-array-of-another-primitive-type/3922/6 "2017-05-25T15:12:44Z")

</div>

The warning not to reinterpret to `Float64` if the data wasn’t originally `Float64` is new to me, can you elaborate?

---

<div class="post-metadata">

### Author: ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)
#### Post date: [May 25, 2017, 3:17pm UTC](https://discourse.julialang.org/t/converting-byte-array-to-an-array-of-another-primitive-type/3922/7 "2017-05-25T15:17:03Z")

</div>

[https://github.com/JuliaLang/julia/pull/21831](https://github.com/JuliaLang/julia/pull/21831)
