# Convert to and from Int24

**URL:** https://discourse.julialang.org/t/convert-to-and-from-int24/7670
**Category:** General Usage
**Tags:** question
**Created:** [December 10, 2017, 10:39am UTC](https://discourse.julialang.org/t/convert-to-and-from-int24/7670 "2017-12-10T10:39:08Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [December 10, 2017, 10:39am UTC](https://discourse.julialang.org/t/convert-to-and-from-int24/7670/1 "2017-12-10T10:39:08Z")

</div>

I am want to try an `Int24` type, purely for storage. It is easy to declare one with

```julia
primitive type Int24 <: Signed 24 end

```

but I am not sure how to access its value.

I only need conversion to and from `Int32`, but I don’t think I can use `reinterpret` because they don’t have the same number of bits. How can I convert to and from `Int32`?

(BTW, I am aware that I destroy alignment and it will degrade performance; it is an experiment)

---

<div class="post-metadata">

### Author: ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)
#### Post date: [December 10, 2017, 10:59am UTC](https://discourse.julialang.org/t/convert-to-and-from-int24/7670/2 "2017-12-10T10:59:02Z")

</div>

Once you find out, it would be great to update the docs with an example like this (or a simpler one).

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [December 10, 2017, 11:12am UTC](https://discourse.julialang.org/t/convert-to-and-from-int24/7670/3 "2017-12-10T11:12:29Z")

</div>

There is an example in [test/intrinsics.jl](https://github.com/JuliaLang/julia/blob/40e7d29f981749f28034bc8dd87645d2a7188f9c/test/intrinsics.jl#L38-L40):

```julia
primitive type Int24 24 end
Int24(x::Int) = Core.Intrinsics.trunc_int(Int24, x)
Int(x::Int24) = Core.Intrinsics.zext_int(Int, x)

```

which actually solves my problem, but it may not be general enough to add to the manual.

---

<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: [December 10, 2017, 6:00pm UTC](https://discourse.julialang.org/t/convert-to-and-from-int24/7670/4 "2017-12-10T18:00:57Z")

</div>

It would be interesting to see how well LLVM supports this these days. Once upon a time, “strange” bit sizes were very poorly supported but it may have gotten better.
