# How to reinterpret Float64 as two Float32's

**URL:** https://discourse.julialang.org/t/how-to-reinterpret-float64-as-two-float32s/10808
**Category:** General Usage
**Tags:** question
**Created:** [May 10, 2018, 12:41am UTC](https://discourse.julialang.org/t/how-to-reinterpret-float64-as-two-float32s/10808 "2018-05-10T00:41:13Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![magzpavz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/magzpavz/32/1822_2.png) [@magzpavz](https://discourse.julialang.org/u/magzpavz)
#### Post date: [May 10, 2018, 12:41am UTC](https://discourse.julialang.org/t/how-to-reinterpret-float64-as-two-float32s/10808/1 "2018-05-10T00:41:13Z")

</div>

`reinterpret` can slice an Int64 into two Int32’s. Is there a way to do this for floats?

Relatedly, is there an inverse of `bits`?

---

<div class="post-metadata">

### Author: ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)
#### Post date: [May 10, 2018, 1:29am UTC](https://discourse.julialang.org/t/how-to-reinterpret-float64-as-two-float32s/10808/2 "2018-05-10T01:29:15Z")

</div>

You can do this by wrapping the Float64 in an array:

```julia
julia> reinterpret(Float32, [1.0])
2-element Array{Float32,1}:
 0.0  
 1.875

```

---

<div class="post-metadata">

### Author: ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)
#### Post date: [May 10, 2018, 4:01pm UTC](https://discourse.julialang.org/t/how-to-reinterpret-float64-as-two-float32s/10808/3 "2018-05-10T16:01:07Z")

</div>

> [@magzpavz](#):
>
> reinterpret can slice an Int64 into two Int32’s.

Yes, and that’s useful, but I doubt it is for floats, even though you can (just interpreting the upper and lower bits).

I’m just curious, what are you really trying to do?

---

<div class="post-metadata">

### Author: ![magzpavz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/magzpavz/32/1822_2.png) [@magzpavz](https://discourse.julialang.org/u/magzpavz)
#### Post date: [May 10, 2018, 6:35pm UTC](https://discourse.julialang.org/t/how-to-reinterpret-float64-as-two-float32s/10808/4 "2018-05-10T18:35:09Z")

</div>

I have some data I saved off an instrument. The file format is not well documented. I knew that the file starts with the model and serial number of the instrument, and then a list of the instrument settings, which are a mix of Int32’s, Float32’s and Float64’s. As I read out the file, if I get a value that seems wacky, I want to reinterpret it.

---

<div class="post-metadata">

### Author: ![simonbyrne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simonbyrne/32/19_2.png) [@simonbyrne](https://discourse.julialang.org/u/simonbyrne)
#### Post date: [May 10, 2018, 6:36pm UTC](https://discourse.julialang.org/t/how-to-reinterpret-float64-as-two-float32s/10808/5 "2018-05-10T18:36:38Z")

</div>

To avoid the array allocation overhead, you can also do:

```julia
u = reinterpret(UInt64, x)
y1 = reinterpret(Float32, (u >> 32) % UInt32)
y2 = reinterpret(Float32, u % UInt32)

```
