From: "QUEISSER,ANDREW (HP-Corvallis,ex1)" Date: 2002-03-30T08:53:41+09:00 Subject: RE: Decimal->Hex try blahblah = sprintf("%x", blah) sprintf actually returns the string, it doesn't write into it. Your example tries to use blahblah as the format string and "%x" and blah as the arguments. > -----Original Message----- > From: Jason DiCioccio [mailto:geniusj@bluenugget.net] > Sent: Friday, March 29, 2002 3:43 PM > To: ruby-talk@ruby-lang.org > Subject: RE: Decimal->Hex > > > irb(main):001:0> blah = 15 > 15 > irb(main):002:0> blahblah = "" > "" > irb(main):003:0> printf("%X", blah) > Fnil > > (looks good so far . . .) > > irb(main):004:0> sprintf(blahblah, "%X", blah) > "" > irb(main):005:0> blahblah > "" > > I had tried this earlier actually with the same results (forgot to > mention it).. I might be doing something wrong this time as well. > Am I missing something simple? :) > > It seems to work in C though: > > ---- > #include > > int > main( void ) > { > int blah = 15; > char blahblah[8]; > > printf("printf: %X\r\n", blah); > sprintf(blahblah, "%X", blah); > printf("after sprintf: %s\r\n", blahblah); > > return( 0 ); > } > ---- > > FYI, ruby 1.6.7 (2002-03-01) [i386-freebsd4] > > Thanks again, > -JD- > > --On Saturday, March 30, 2002 8:28 AM +0900 "QUEISSER,ANDREW > (HP-Corvallis,ex1)" wrote: > > > You can use sprintf, just like in the good old C days > > but in Ruby sprintf returns a string. > > > > Andrew > > > > > >> -----Original Message----- > >> From: DiCioccio, Jason [mailto:jdicioccio@epylon.com] > >> Sent: Friday, March 29, 2002 2:51 PM > >> To: ruby-talk@ruby-lang.org > >> Subject: Decimal->Hex > >> > >> > >> > >> -----BEGIN PGP SIGNED MESSAGE----- > >> Hash: SHA1 > >> > >> I have a feeling I might be missing something very simple > >> here. But I found > >> a method to convert a string representing a hexadecimal value > >> into a Fixnum > >> (String#hex). Is there a way to convert it back now? > >> > >> Thanks in advance, > >> - -JD- > >> > >> -----BEGIN PGP SIGNATURE----- > >> Version: PGP 7.0.4 > >> > >> iQA/AwUBPKTx/b8+wXo6G32BEQJXpwCfcBbLelw6YnmK6K3Vj4+U9SrIf4kAniTQ > >> aMuPsAT8EmEu1FxjG1NRdiFj > >> =iqTS > >> -----END PGP SIGNATURE----- > >> > >