Convert a slice of BitArray to decimal


#1

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?


#2

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.