----------------------------------- Insectoid Wed Dec 17, 2008 1:38 pm illegal radix 0 ----------------------------------- I'm getting an error 'illegal radix 0' in my (rather inefficient and messy) bin/octal => decimal converter on this line: #base is the base of the number (base, 2, base 8, etc.) #temp is an integer of base temp.to_s.length.times do |i| answer += (temp.to_s(i).to_i) * (base^i) end ----------------------------------- wtd Wed Dec 17, 2008 1:42 pm RE:illegal radix 0 ----------------------------------- irb(main):002:0> 15.to_s 0 ArgumentError: illegal radix 0 from (irb):2:in `to_s' from (irb):2 ----------------------------------- Tony Wed Dec 17, 2008 2:01 pm Re: illegal radix 0 ----------------------------------- (base^i) ^ is XOR. ** is exp irb >> 2^2 => 0 >> 2**2 => 4 ----------------------------------- btiffin Wed Dec 17, 2008 2:16 pm RE:illegal radix 0 ----------------------------------- insectoid; to_s wants a base to convert to. Starts at 2. try irb and > 1234.to_s(2) => "10011010010" > 1234.to_s(16) => "4d2" Cheers ----------------------------------- Insectoid Wed Dec 17, 2008 2:58 pm RE:illegal radix 0 ----------------------------------- btiffin, you have just completely nullified the entire purpose of this project by telling me this. Thanks. (sarcasm heavy there). But thanks, that will help me out. ----------------------------------- Tony Wed Dec 17, 2008 3:22 pm RE:illegal radix 0 ----------------------------------- just because there's a build in method, does not mean that you can't rewrite it for practice anyway. Better yet, now you have a method to spec against. ----------------------------------- btiffin Wed Dec 17, 2008 3:37 pm RE:illegal radix 0 ----------------------------------- I agree with Tony. ;) And as he pointed out, you should practise. (things like ^ vs **). 10,000 hours is a lot of hours. And we need more experts. Not that you may want to be an expert at Ruby ... but I'll advise anyone to pick a few topics and struggle to level of expert. Knowing full well that any given human only gets to pick 1, 2 maybe 3. Cheers ----------------------------------- Insectoid Wed Dec 17, 2008 3:55 pm RE:illegal radix 0 ----------------------------------- Yeah, Ruby is one I want to master. I didn't mean that I'm not going to do it because there's already a method, rather that when it's done, it will remain rather useless. I want to master Ruby, Java, and one of the C's (Java, just because it's so stupid I want to be able to say, ha! I beat you!) ----------------------------------- wtd Wed Dec 17, 2008 4:43 pm RE:illegal radix 0 ----------------------------------- Useless code is what education is all about! ;-)