Ask a Question related to Ruby, Design and Development.
-
Volker Grabsch #1
Base of Numbers
Hello Folks!
I just wanted to know if there's any way except "printf"
to print out (or convert to string) a number using a
different base than 10.
There's "to_s()" for Integers taking a base, but is there
anything within the "#{i}"-syntax, within the contructors
or within the language?
... anything except printf that allows me to change the
base of a number?
Thanks,
--
Volker Grabsch
---<<(())>>---
\frac{\left|\vartheta_0\times\{\ell,\kappa\in\Re\} \right|}{\sqrt
[G]{-\Gamma(\alpha)\cdot\mathcal{B}^{\left[\oint\!c_\hbar\right]}}}
Volker Grabsch Guest
-
find country base on ip
Hey Paul, Love this CFC. :) A couple questions I'm anticipating having to answer include, how often is the database updated and by what... -
Data Base Connection
Hi! I will Know what I do for connect director with MySQL database. I Know xtras like ADO, But this is limited to remote only databasing while it... -
Base conversion
How exactly would you convert to/from a specific, arbitrary base (in this case, 54)? -
Data Base Select
I have an ActiveX control and some data base results on the same web page. I want to respond to an event and change the results from the data base... -
web base image app
hi, im looking for an online graphics app. if at all possible i dont want to have to build it from scratch but i do want to be able to... -
Volker Grabsch #2
Base of Numbers
Sorry, small self-correction:
In article <bdurb0$3o4$01$1@news.t-online.com>, Volker Grabsch wrote:<no>> Hello Folks!
>
> I just wanted to know if there's any way except "printf"
> to print out (or convert to string) a number using a
> different base than 10.
>
> There's "to_s()" for Integers taking a base, but is there
Well, this makes more sense ...> anything within the "#{i}"-syntax, within the contructors
> or within the language?
>
> .. anything except printf that allows me to change the
> base of a number?
>
>
> Thanks,
--
Volker Grabsch
---<<(())>>---
\frac{\left|\vartheta_0\times\{\ell,\kappa\in\Re\} \right|}{\sqrt
[G]{-\Gamma(\alpha)\cdot\mathcal{B}^{\left[\oint\!c_\hbar\right]}}}
Volker Grabsch Guest
-
ts #3
Re: Base of Numbers
>>>>> "V" == Volker Grabsch <volker_grabsch@v.notjusthosting.com> writes:
V> <no>>> There's "to_s()" for Integers taking a base, but is there
In 1.8, #to_s can take an argument
svg% ruby -e 'p 12.to_s(16); p 12.to_s(12)'
"c"
"10"
svg%
perhaps #sprintf ???>> .. anything except printf that allows me to change the
>> base of a number?
Guy Decoux
ts Guest
-
Nobuyoshi Nakada #4
Re: Base of Numbers
Hi,
At Thu, 3 Jul 2003 07:25:30 +0900,
Josef 'Jupp' Schugt wrote:Also String#to_i.> to_s works for any basis from 2 to 36 using these digits:
>
> 0, 1, 2, 3, 4, 5, 6, 7, 8, 0, a, b, c, d, e, f, g, h,
> i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z
$ grep -w 36 sample/test.rb
test_ok("Just".to_i(36) == 926381)
test_ok("-another".to_i(36) == -23200231779)
test_ok(1299022.to_s(36) == "ruby")
test_ok(-1045307475.to_s(36) == "-hacker")
test_ok("Just_another_Ruby_hacker".to_i(36) == 265419172580680477752431643787347)
test_ok(-265419172580680477752431643787347.to_s(36) == "-justanotherrubyhacker")
--
Nobu Nakada
Nobuyoshi Nakada Guest
-
Tom Felker #5
Re: Base of Numbers
On Wed, 2003-07-02 at 17:25, Josef 'Jupp' Schugt wrote:
> Saluton!
>
> * Dave Thomas; 2003-07-02, 20:26 UTC:>> > This is a test 'ri'. Please report errors and omissions
> > on [url]http://www.rubygarden.org/ruby?RIOnePointEight[/url]
> >
> > ------------------------------------------------------------ Fixnum#to_s
> > fix.to_s( base=10 ) -> aString
> >
> > ------------------------------------------------------------------------
> > Returns a string containing the representation of fix radix base
> > (2, 8, 10, or 16).
> > 12345.to_s #=> "12345"
> > 12345.to_s(2) #=> "11000000111001"
> > 12345.to_s(8) #=> "30071"
> > 12345.to_s(10) #=> "12345"
> > 12345.to_s(16) #=> "3039"
> to_s works for any basis from 2 to 36 using these digits:
>
> 0, 1, 2, 3, 4, 5, 6, 7, 8, 0, a, b, c, d, e, f, g, h,
> i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z
>
> Gis,
>
> Josef 'Jupp' Schugt
Cool. Is there a way to from a string to an int with any base?
--
Tom Felker <tcfelker@mtco.com>
Tom Felker Guest
-
zunda #6
Re: Base of Numbers
Hello,
or> |Cool. Is there a way to from a string to an int with any base?
>
> String#to_s(base=10)
String#to_i(base=10)?
% ruby -ve 'puts "100".to_i(base=16)'
ruby 1.8.0 (2003-07-02) [i686-linux]
256
Best regards,
zunda
zunda Guest



Reply With Quote

