Non-decimal radices/Convert: Difference between revisions

Content added Content deleted
(Slate implementation)
Line 647: Line 647:
<lang ruby>s = 26.to_s(16) # returns the string 1a
<lang ruby>s = 26.to_s(16) # returns the string 1a
i = '1a'.to_i(16) # returns the integer 26</lang>
i = '1a'.to_i(16) # returns the integer 26</lang>
Caution: <tt>to_i</tt> simply stops when it reaches an invalid character; it does not raise any exceptions. So sometimes it may appear to parse something and get a result, but it is only based on part of the input string:
<lang ruby>"59".to_i(7) # returns 5, but this is probably not what you wanted</lang>


=={{header|Slate}}==
=={{header|Slate}}==