I need to convert an array of integers to a small bot string using Ruby. Any links or tips would be appreciated.
example says [2,7,9,11] => "4205"
a = [2,7,9,11]
b = [1,2,3,4]
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?
source
share