num = "0000001000000000011000000000000010010011000011110000000000000000"
for n in 0...num.length
temp = num[n]
dec = dec + temp*(2**(num.length - n - 1))
end
puts dec
當我在irb中運行此代碼時,以下錯誤消息是輸出。當我在python中編譯相同的邏輯時,它工作得很好。我用Google搜索「的RangeError:BIGNUM太大而轉換成'長':但是沒有找到相關的答案 請幫我:(在此先感謝RangeError:bignum太大,無法轉換爲'long'
RangeError: bignum too big to convert intolong' from (irb):4:in
*' from (irb):4:inblock in irb_binding' from (irb):2:in
each' from (irb):2 from C:/Ruby193/bin/irb:12:in `'
正如我下面所說的,Ruby有'num.to_i(2)'形式的這種內置形式:-) – 2012-04-05 07:55:30