Harold Hausman
3/26/2007 4:06:00 AM
On 3/26/07, Ak 756 <macro.peng@gmail.com> wrote:
> Mike Moore wrote:
>
> > irb(main):008:0> int_to_binary(903)
> > => "001110000111"
>
> Hi ,thanks for advise.
> I want my function to give output 100100000011 for input 903. Where
> '1001','0000','0011' is the binary value for 9,0,3
> Is there efficient way to do this?
>
I don't know about efficent, but you could start with something like
this and see if it's performant enough:
irb(main):002:0> 903.to_s.split("").each {|digit| p digit.to_i.to_s(2)}
"1001"
"0"
"11"
Meh, actually, I bet someone else can do better than that, but I'm at
work right now. (:
-Harold