# Converting an Array of Byte to Array{T}

**URL:** https://discourse.julialang.org/t/converting-an-array-of-byte-to-array-t/53676
**Category:** General Usage
**Tags:** question, binaryio, array
**Created:** [January 20, 2021, 4:16pm UTC](https://discourse.julialang.org/t/converting-an-array-of-byte-to-array-t/53676 "2021-01-20T16:16:15Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Clonkk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/clonkk/32/20088_2.png) [@Clonkk](https://discourse.julialang.org/u/Clonkk)
#### Post date: [January 20, 2021, 4:16pm UTC](https://discourse.julialang.org/t/converting-an-array-of-byte-to-array-t/53676/1 "2021-01-20T16:16:15Z")

</div>

Hello,

I have binary data read from SQLite database in the form of Array{Uint8}.

What would be the best solution to convert this binary data into an Array{T} (`convert` function perform element wise conversion and thus do not work).

For example if I have :

```julia
A = [0x00 0x00 0x00 0x01 0x00 0x00 0x01 0x00] 
B = bufferConvert{Int32}(A) # How to implement buffer convert ?
# B is now equal to [1 256]

```

---

<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: [January 20, 2021, 4:21pm UTC](https://discourse.julialang.org/t/converting-an-array-of-byte-to-array-t/53676/2 "2021-01-20T16:21:03Z")

</div>

You can use `reinterpret` to treat your array of bytes as an array of some other bitstype:

```julia
julia> reinterpret(Int32, vec(A))
2-element reinterpret(Int32, ::Array{UInt8,1}):
 16777216
    65536

```

Note that I had to use `vec` because your `A` is actually a 1x8 matrix, not a vector. Storing `A` as a vector (using commas instead of spaces as delimiters) would remove that issue.

Note also that this gives the wrong answer, presumably because you are expecting a different endianness. Using `ntoh` fixes that:

```julia
julia> ntoh.(reinterpret(Int32, vec(A)))
2-element Array{Int32,1}:
   1
 256

```

---

<div class="post-metadata">

### Author: ![Clonkk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/clonkk/32/20088_2.png) [@Clonkk](https://discourse.julialang.org/u/Clonkk)
#### Post date: [January 20, 2021, 4:25pm UTC](https://discourse.julialang.org/t/converting-an-array-of-byte-to-array-t/53676/3 "2021-01-20T16:25:31Z")

</div>

Ah it was what I was looking for indeed !

Yes, my examplle was just to illustrate what I meant. `typeof(input)` is `Array{Uint8, 1}`.
