Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 illegal radix 0
Index -> Programming, Ruby -> Ruby Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Insectoid




PostPosted: Wed Dec 17, 2008 1:38 pm   Post subject: illegal radix 0

I'm getting an error 'illegal radix 0' in my (rather inefficient and messy) bin/octal => decimal converter on this line:
Ruby:

#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
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: Wed Dec 17, 2008 1:42 pm   Post subject: RE:illegal radix 0

code:
irb(main):002:0> 15.to_s 0
ArgumentError: illegal radix 0
        from (irb):2:in `to_s'
        from (irb):2
Tony




PostPosted: Wed Dec 17, 2008 2:01 pm   Post subject: Re: illegal radix 0

insectoid @ Wed Dec 17, 2008 1:38 pm wrote:
(base^i)

^ is XOR. ** is exp
code:

irb
>> 2^2
=> 0
>> 2**2
=> 4
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
btiffin




PostPosted: Wed Dec 17, 2008 2:16 pm   Post subject: RE:illegal radix 0

insectoid;

to_s wants a base to convert to.

Starts at 2.
try irb and
code:

> 1234.to_s(2)
=> "10011010010"

> 1234.to_s(16)
=> "4d2"


Cheers
Insectoid




PostPosted: Wed Dec 17, 2008 2:58 pm   Post subject: 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




PostPosted: Wed Dec 17, 2008 3:22 pm   Post subject: 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
btiffin




PostPosted: Wed Dec 17, 2008 3:37 pm   Post subject: RE:illegal radix 0

I agree with Tony. Wink 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




PostPosted: Wed Dec 17, 2008 3:55 pm   Post subject: 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!)
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: Wed Dec 17, 2008 4:43 pm   Post subject: RE:illegal radix 0

Useless code is what education is all about! Wink
Display posts from previous:   
   Index -> Programming, Ruby -> Ruby Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 9 Posts ]
Jump to:   


Style:  
Search: