我正在尝试将字符串转换为二进制文件: puts "Tell me a number:"num1 = getsputs "The number you gave in binary is " + num1.to_s(2) 但是我得到了“错误的参数数量(1到0)”错误. 有关如何进行的任何建议?
puts "Tell me a number:" num1 = gets puts "The number you gave in binary is " + num1.to_s(2)
但是我得到了“错误的参数数量(1到0)”错误.
有关如何进行的任何建议?
您需要先将您获得的字符串转换为数字puts "The number you gave in binary is " + num1.to_i.to_s(2)