Binary String to Integer?

P

Peter Marsh

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

two = '10'

string_to_int(two)

=> 2
 
D

Drew Olson

Peter said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,252
Messages
2,571,267
Members
47,908
Latest member
MagdalenaR

Latest Threads

Top