Tim Hunter
10/8/2004 2:12:00 PM
Ray Pendergraph wrote:
> I am sort of a novice to Ruby so I will just start out with a
> simplified example what I want to do. I have an array with two bytes
> in it [0x03,0x9A] and depending on what the byte order of the file
> (not the architecture) is want to display these bytes as 922 or 39427
> (both unsigned shorts). I want to do this without reversing the index
> on the array or anything goofy like that. Whats the most proper way to
> do this in Ruby? I suspect my solution lies somewhere in pack... I
> toyed with it briefly but decided to ask.
I don' t know if this is goofy or not, but here goes:
irb(main):005:0> a = [0x03,0x9a]
=> [3, 154]
irb(main):006:0> p (a[0]<<8)+a[1]
922
=> nil
irb(main):007:0> p (a[1]<<8)+a[0]
39427
=> nil
irb(main):008:0>