Binary String to Integer?


#1

How can you translate a binary string into an integer? i.e.

two = ‘10’

string_to_int(two)

=> 2


#2

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