[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Simple Q: bit string -> integer

Todd

5/6/2007 2:08:00 PM

Is there a simple way to induce a bit string into an
integer; for example, "10010000" into 144? And also,
to show a Fixnum in its different representations
(hex, num, binary)?

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail...

2 Answers

Harry Kakueki

5/6/2007 2:21:00 PM

0

On 5/6/07, Todd Benson <toddkennethbenson@yahoo.com> wrote:
> Is there a simple way to induce a bit string into an
> integer; for example, "10010000" into 144? And also,
> to show a Fixnum in its different representations
> (hex, num, binary)?
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail...
>
>


Try this

str = "10010000"
p str.to_i(2)
puts
p 255.to_s(16)
p 255.to_s(2)

Harry

--
http://www.kakueki.com/ruby...
A Look into Japanese Ruby List in English

Florian Frank

5/6/2007 2:38:00 PM

0

Todd Benson wrote:
> Is there a simple way to induce a bit string into an
> integer; for example, "10010000" into 144?

"10010000".to_i(2)

> And also,
> to show a Fixnum in its different representations
> (hex, num, binary)?

144.to_s(16), 144.to_s(2)

But what's "num"?

--
Florian Frank