# Convert a slice of BitArray to decimal

**URL:** <https://discourse.julialang.org/t/convert-a-slice-of-bitarray-to-decimal/4036>\
**Category:** General Usage\
**Created:** [June 1, 2017, 3:03pm UTC](https://discourse.julialang.org/t/convert-a-slice-of-bitarray-to-decimal/4036 "2017-06-01T15:03:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![novatena](https://avatars.discourse-cdn.com/v4/letter/n/c68b51/32.png) [@novatena](https://discourse.julialang.org/u/novatena)\
**Post date:** [June 1, 2017, 3:03pm UTC](https://discourse.julialang.org/t/convert-a-slice-of-bitarray-to-decimal/4036/1 "2017-06-01T15:03:37Z")

</div>

I am writing a function which process a BitVector of length N. Each time, it processes a chunk of k bits (k is often between 1 and 20). Basically, I need to compute the hamming hamming distance of this chunk of bits with some other BitArray of length k.

Currently, for small value of k, i just convert all chunk of bits to decimal number and do lookup with a pre-created table. So everytime, I have to do some overhead calculation to get the decimal number from the input bits.

Is there any fast way to compute hamming distance of two BitVectors? Or is there any fast convertion to decimal number?

---

<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:** [June 1, 2017, 3:09pm UTC](https://discourse.julialang.org/t/convert-a-slice-of-bitarray-to-decimal/4036/2 "2017-06-01T15:09:57Z")

</div>

I don’t know how you manage the lookup table, but if it is something that can be addressed using `Tuple{BitVector,BitVector}`, eg `Dict`, you could look them up directly.

For the calculation, would `sum(xor(a,b))` work? You may want to benchmark whether memoization improves on it, since it may be very fast as is.
