From: Simon ARNAUD Date: 2002-02-26T10:24:47+09:00 Subject: Re: How to convert "1110" to 14, "0111" to 7, etc. You are looking for the oct method. "0b1110".oct => 14 I'm not sure the method was meant to work with bin, but it does. However, I didn't managed to find a solution without using a temp var a = "0b" + binstr num = a.oct If someone knows a way, please post it Simon ARNAUD aka Maz On Tue, 26 Feb 2002 01:08:08 +0100, andrew queisser wrote: > How can I convert a string of binary digits to a number? I've got this > but I imagine there's some kind of built-in method. Is there? > > def BinStrToNum ( binStr ) > sum = 0 > digit = 1 > binStr.reverse.each_byte { |i| > sum += (i-48)*digit > digit <<= 1 > } > return sum > end > > Thanks, > Andrew