On 11/23/05, Curt Hibbs <curt.hibbs / gmail.com> wrote:
> On 11/23/05, Ryan Leavengood <leavengood / gmail.com> wrote:
> >
> > On 11/22/05, James Edward Gray II <james / grayproductions.net> wrote:
> > >
> > >  >> bits = Array.new(8) { |i| 7[i] }.reverse!
> > > => [0, 0, 0, 0, 0, 1, 1, 1]
> >
> > And the winner by a nose is
...
> > James!!!
> >

def to_ba(num, size=8)
  (-size+1..0).inject({}) {|x,i| x << num[-i]}
end

to_ba(15)
 => [0,0,0,0,1,1,1,1]

It may be a tad faster, the bigger the array, due to the lack of
reverse. Can someone bench it? I don't have require 'quickbench'

Or perhaps, modifying James':

def to_ba(num, size=8)
  Array.new(size) {|i| num[-i+size-1]}
end

Ed