I need to convert an array of integers to a little endian bitmask using Ruby. Any links or hints would be appreciated.
the example says [2,7,9,11] => "4205"
a = [2,7,9,11] # 4205
b = [1,2,3,4] # 0F00
def array_to_mask(arr)
mask = 0
arr.each do |i|
mask = mask | (1 << i)
end
return mask.to_s(16)
end
p array_to_mask(a) # a84
p array_to_mask(b) # 1e
This does not work, but am i on the right track?