Forum: Ruby Binary String to Integer?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Peter M. (Guest)
on 2007-05-16 22:14
How can you translate a binary string into an integer? i.e.

two = '10'

string_to_int(two)

=> 2
Drew O. (Guest)
on 2007-05-16 22:19
Peter M. wrote:
> How can you translate a binary string into an integer? i.e.
>
> two = '10'
>
> string_to_int(two)
>
> => 2

irb(main):001:0> two = '10'
=> "10"
irb(main):002:0> two.to_i(2)
=> 2

The argument for #to_i is the base for converting the string to an int.

-Drew
This topic is locked and can not be replied to.