From: Ryan Leavengood Date: 2005-11-23T08:11:46+09:00 Subject: Re: How convert an integer to a bit array On 11/22/05, Ryan Leavengood wrote: > > This way is about 4 times faster than James' version: For those curious: ---------------------------------------------------------------------- | QuickBench Session Started | | 100000 Iterations | ---------------------------------------------------------------------- user system total real 1. 244.to_ba 1.171000 0.000000 1.171000 ( 1.172000) 2. ("%b" % 244).split(... 4.735000 0.000000 4.735000 ( 4.750000) 3. s.unpack("B*")[0].s... 4.156000 0.000000 4.156000 ( 4.156000) 4. 244.to_s(2).split("... 4.422000 0.000000 4.422000 ( 4.437000) ---------------------------------------------------------------------- | Fastest was <1. 244.to_ba> | ---------------------------------------------------------------------- QuickBench is a little script I wrote, which I may or may not release into the wild. The code will follow my name (note how I use the DATA section for the things to benchmark): Ryan "Mr. Benchmark" Leavengood class Integer def to_ba(size=8) a=[] (size-1).downto(0) do |i| a<