Thread: Binary to Decimal... Help needed....

  1. #1
    huochai
    Guest

    Unhappy Binary to Decimal... Help needed....

    Hi all,
    Is there any sample program for converting Binary number to Decimal number in C..
    I can find program in C++ only...
    Thanks in advance,
    xiao guang

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Have you tried understanding the C++ code and then writing your own program?
    My best code is written with the delete key.

  3. #3
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,490
    I'm assuming you want to convert an integer like 110011 to decimal?

    Find out how to deal with each digit seperately, then add it back with a power of 2 instead of 10.

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>Binary number
    Can you confirm your meaning of this term. What variable type are you converting from?
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    GuiltySpark343
    Guest

    Binary to Decimal

    Binary and Decimal are the same thing-- simply different representations. You didn't ask for text conversions, Reclaimer, so that isn't discussed in this index.

    Since binary is base-2, it's very easy.

    1) What is your value-size? long, short, byte?
    2) Create a mask for the high-bit
    3) test the value against that mask to determine value of set/cleared bit.
    4) right-shift the mask by one, and go back to step 3 until all bits tested
    5) convert resulting value to a string (if that's what you want) and display as decimal.

    If you're just using string conversions, then use the string library.

    Ah, I must go. The Flood have breached a plasma conduit on level 6 so I must reenergize the drone subsystem.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. binary to decimal
    By rs07 in forum C Programming
    Replies: 3
    Last Post: 09-14-2008, 12:52 PM
  2. Replies: 3
    Last Post: 07-04-2008, 12:39 PM
  3. Replies: 9
    Last Post: 10-07-2006, 05:37 AM
  4. decimal to binary
    By bugeye in forum C Programming
    Replies: 5
    Last Post: 03-13-2002, 11:50 AM
  5. decimal to binary, decimal to hexadecimal and vice versa
    By Unregistered in forum C++ Programming
    Replies: 9
    Last Post: 12-08-2001, 11:07 PM