# Covert BitArray to Int64

**URL:** <https://discourse.julialang.org/t/covert-bitarray-to-int64/9193>\
**Category:** General Usage\
**Created:** [February 20, 2018, 5:38am UTC](https://discourse.julialang.org/t/covert-bitarray-to-int64/9193 "2018-02-20T05:38:20Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)\
**Post date:** [February 20, 2018, 2:20pm UTC](https://discourse.julialang.org/t/covert-bitarray-to-int64/9193/4 "2018-02-20T14:20:18Z")

</div>

```julia
function revbits(z::UInt64)
           z = (((z & 0xaaaaaaaaaaaaaaaa) >> 1) | ((z & 0x5555555555555555) << 1))
           z = (((z & 0xcccccccccccccccc) >> 2) | ((z & 0x3333333333333333) << 2))
           z = (((z & 0xf0f0f0f0f0f0f0f0) >> 4) | ((z & 0x0f0f0f0f0f0f0f0f) << 4))
           z = (((z & 0xff00ff00ff00ff00) >> 8) | ((z & 0x00ff00ff00ff00ff) << 8))
           z = (((z & 0xffff0000ffff0000) >> 16) | ((z & 0x0000ffff0000ffff) << 16))
           z = (((z & 0xffffffff00000000) >> 32) | ((z & 0x00000000ffffffff) << 32))
           return z
       end

```

not the fastest (table lookups are) but handy

---

_[View the full topic](https://discourse.julialang.org/t/covert-bitarray-to-int64/9193)._
