Erlang bit indexing

Posted by GTDev on Stack Overflow See other posts from Stack Overflow or by GTDev
Published on 2012-06-08T22:16:30Z Indexed on 2012/06/08 22:40 UTC
Read the original article Hit count: 287

Filed under:
|
|
|
|

I am currently trying to learn erlang and what I am trying to do is to perform an operation on specific indices of an array stored in a bit array or int. If there is a 0 in a position, the index into the array at that position is not used.

So envision the following:

Example the array is: [1, 3, 5, 42, 23]
My bit array is: 21 = 10101 in binary
so I'm using indicies 1,3,5
so I'm calling a function on [1, 5, 23]

my function is of the form

my_function(Array, BitArray) ->
    SubArray = get_subarray_from_bitarray(Array, BitArray),
    process_subarray(SubArray).

And I need help with the get_subarray_from_bitarray(). I know erlang has special syntax around bit strings (something like <<>>) so is there an efficient way of indexing into the bit array to get the indicies?

© Stack Overflow or respective owner

Related posts about list

Related posts about binary