Return to Snippet

Revision: 17445
at September 4, 2009 18:15 by AzizLight


Updated Code
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)

Revision: 17444
at September 4, 2009 18:15 by AzizLight


Initial Code
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)

Initial URL

                                

Initial Description

                                

Initial Title
Binary to decimal terminal script

Initial Tags
textmate, ruby, terminal

Initial Language
Ruby