Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Ruby (http://www.velocityreviews.com/forums/f66-ruby.html)
-   -   How do you convert a hexadecimal number to a binary number? (http://www.velocityreviews.com/forums/t850636-how-do-you-convert-a-hexadecimal-number-to-a-binary-number.html)

 Bob Sanders 05-30-2008 10:55 AM

How do you convert a hexadecimal number to a binary number?

I can't find a clue how to convert a hexadecimal number to a binary
number. Anyone know?
--
Posted via http://www.ruby-forum.com/.

 Oscar Del Ben 05-30-2008 11:02 AM

Re: How do you convert a hexadecimal number to a binary number?

[Note: parts of this message were removed to make it a legal post.]

number.to_s(2)

2008/5/30, Bob Sanders <small.business.strategy@gmail.com>:
>
> I can't find a clue how to convert a hexadecimal number to a binary
> number. Anyone know?
>
> --
> Posted via http://www.ruby-forum.com/.
>
>

 Bill Kelly 05-30-2008 11:04 AM

Re: How do you convert a hexadecimal number to a binary number?

From: "Bob Sanders" <small.business.strategy@gmail.com>
>
>I can't find a clue how to convert a hexadecimal number to a binary
> number. Anyone know?

>> "beef".to_i(16).to_s(2)

=> "1011111011101111"

Regards,

Bill

 Ryan Lewis 05-30-2008 11:34 AM

Re: How do you convert a hexadecimal number to a binary numb

Bob Sanders wrote:
> I can't find a clue how to convert a hexadecimal number to a binary
> number. Anyone know?

> You have to convert items using methods such as String#to_i(base=10)
> and Fixnum#to_s(base=10). These would be for decimal values. Change
> to (base=16) for hexadecimal values, (base=2) for binary values,

etc.
--
Posted via http://www.ruby-forum.com/.

 Bob Sanders 05-30-2008 11:44 AM

Re: How do you convert a hexadecimal number to a binary numb

Ryan Lewis wrote:
> Bob Sanders wrote:
>> I can't find a clue how to convert a hexadecimal number to a binary
>> number. Anyone know?

>
> > You have to convert items using methods such as String#to_i(base=10)
> > and Fixnum#to_s(base=10). These would be for decimal values. Change
> > to (base=16) for hexadecimal values, (base=2) for binary values,

> etc.

Big thanks for the quick reply, Ryan!
--
Posted via http://www.ruby-forum.com/.

 Ryan Lewis 05-30-2008 11:50 AM

Re: How do you convert a hexadecimal number to a binary numb

Bob Sanders wrote:
> Big thanks for the quick reply, Ryan!

NP, I just happened to needed this same info like two days ago
--
Posted via http://www.ruby-forum.com/.

 All times are GMT. The time now is 11:37 AM.