Thread: Converting decimal to binary

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    2

    Converting decimal to binary

    I need to take a decimal base 10 number supplied by the user and convert it to binary. Is there an equation for this? What would the code look like?

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    There's a FAQ on bitwise operators you could always read. Or you could search the forum, since this gets asked all the time.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User TactX's Avatar
    Join Date
    Oct 2005
    Location
    Germany.Stuttgart
    Posts
    65
    With "convert" you think about printing out the binary digits? If so, look up bitwise operators and/or the modulo operator.

  4. #4
    Registered User cbastard's Avatar
    Join Date
    Jul 2005
    Location
    India
    Posts
    167
    Just code what you do on paper.
    input in decimal is x
    while x is greater than 0
    a is x%2
    store a in char array
    x is x/2
    increment array index
    end loop

    ***if your convert mean binary equivalent of decimal no.
    Long time no C. I need to learn the language again.
    Help a man when he is in trouble and he will remember you when he is in trouble again.
    You learn in life when you lose.
    Complex problems have simple, easy to understand wrong answers.
    "A ship in the harbour is safe, but that's not what ships are built
    for"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Converting 32 bit binary IP to decimal IP (vice-versa)
    By Mankthetank19 in forum C Programming
    Replies: 15
    Last Post: 12-28-2009, 07:17 PM
  2. Converting decimal to binary within a I/O program
    By RandomX in forum C Programming
    Replies: 4
    Last Post: 11-26-2006, 09:25 AM
  3. Confused by expression.
    By Hulag in forum C Programming
    Replies: 3
    Last Post: 04-07-2005, 07:52 AM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  5. Converting decimal to binary?
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 04-17-2002, 08:21 AM