From: Caleb Tennis Date: 2005-11-23T07:40:07+09:00 Subject: Re: How convert an integer to a bit array > > > s = "" > s[0] = 7 > s.unpack("B*")[0].split("").map{|bit|bit.to_i} > => [0, 0, 0, 0, 0, 1, 1, 1] > > > > It should be easier than that, though. > How about: num = 50 num.to_s(2).split("").map{ |bit| bit.to_i} There's problably some trickery with String.each_with_index you can do to make the map a little simpler.