/ Published in: Ruby

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
def decimal_to_binar(x) z = [] while x >= 1 z << x % 2 x /= 2 end z.reverse.join(" ") end number = gets.chomp puts "decimal : #{number}nbinary : #{decimal_to_binar(number.to_i)}"
Comments
