Simple Q: bit string -> integer

T

Todd Benson

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.yahoo.com
 
H

Harry Kakueki

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.yahoo.com


Try this

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

Harry
 
F

Florian Frank

Todd said:
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"?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

daemons 0
What is the meaning of Dim 6
Magazine name 1
where does song.name come from? 3
specifying path 1
:: and . 6
Leaving Python List 1
entire stack trace 5

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top