/ Published in: Ruby
Expand |
Embed | Plain Text
def binary_to_decimal(x) y = 1 z = 0 x.gsub(/ /,'').reverse.scan(/(0|1)/).each do |x| z = z + (y * x[0].to_i) y *= 2 end z end number = gets.chomp puts binary_to_decimal(number)
You need to login to post a comment.
