From: Sebastian Hungerecker Date: 2010-05-17T07:12:44+09:00 Subject: Re: Array conversion On 16.05.2010 23:58, Paul A. wrote: > I have a array of 32 bits digests such as this one: > > array = [1717922406, 543519338, 543585641, 1701343776, 1718969704, > 544368245, 1751457906, 1713399157] > > And I would like to convert it into another array of 128 bits digests. > > According so test, I think the such array is: > [136107835579490162288229994478942319136, > 136190811075650685875822190301307495797] > > Do you know if there is a simple way to do a such array conversion. > Group the array into slices of 4 and then "concatenate" each slice by shifting and adding: array.each_slice(4).map do |slice| slice.inject(0) do |sum,ele| (sum<<32) + ele end end #=> [136107835579490162288229994478942319136, 136190811075650685875822190301307495797]