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

Discussion in 'Ruby' started by Bob Sanders, May 30, 2008.

  1. Bob Sanders

    Bob Sanders Guest

    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/.
     
    Bob Sanders, May 30, 2008
    #1
    1. Advertising

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

    number.to_s(2)

    2008/5/30, Bob Sanders <>:
    >
    > 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, May 30, 2008
    #2
    1. Advertising

  3. Bob Sanders

    Bill Kelly Guest

    From: "Bob Sanders" <>
    >
    >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
     
    Bill Kelly, May 30, 2008
    #3
  4. Bob Sanders

    Ryan Lewis Guest

    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?


    From http://www.tek-tips.com/viewthread.cfm?qid=1026407&page=1
    > 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/.
     
    Ryan Lewis, May 30, 2008
    #4
  5. Bob Sanders

    Bob Sanders Guest

    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?

    >
    > From http://www.tek-tips.com/viewthread.cfm?qid=1026407&page=1
    > > 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/.
     
    Bob Sanders, May 30, 2008
    #5
  6. Bob Sanders

    Ryan Lewis Guest

    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/.
     
    Ryan Lewis, May 30, 2008
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Eric
    Replies:
    3
    Views:
    1,084
    Bengt Richter
    Apr 22, 2004
  2. muss
    Replies:
    13
    Views:
    727
    Vladimir S. Oka
    Mar 27, 2006
  3. Replies:
    7
    Views:
    2,948
    Martin Ambuhl
    Dec 27, 2006
  4. Replies:
    6
    Views:
    641
    Keith Thompson
    Sep 2, 2007
  5. Replies:
    6
    Views:
    507
    Barry Schwarz
    Sep 4, 2007
Loading...

Share This Page