need some help here??

This is a discussion on need some help here?? within the C Programming forums, part of the General Programming Boards category; Does anyone can help me.?? Does anyone know how to build a programme that can receive binary number and convert ...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    4

    Question need some help here??

    Does anyone can help me.??

    Does anyone know how to build a programme that can receive binary number and convert it to decimal number.

    Thank You, hope there's anyone can solve my problem..

  2. #2
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    You mean a number represented in binary should be converted to decimal?

    Just a little hint

    If binary representation is: bn ... b2 b1 b0

    Decimal value = b0 2^0 + b1 2^1 + b2 2^2 + ... + bn 2^n

    I guess you now have the information for conversion. It shouldn't be too hard to create an algorithm for this and implement it in C. But if you have more questions, just ask them.

  3. #3
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Yes, it's just a simple matter of reading in the eight 0's and/or 1's and converting them with the base two.
    1978 Silver Anniversary Corvette

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    4
    Thanks a lot....why I didn't think about it before...

    Now i remember that we use that formula in math for te same reason....

    thanks for reminding me...but if problems occur, I'll ask again...

    but I have another question,

    Is it possible to determine character count in one word or phrase without using any string.h and how?

    Thanks again..

  5. #5
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    >Is it possible to determine character count in one word or
    >phrase without using any string.h and how?

    I don't exactly get what you mean. Do you mean if it is possible to get the length of a string without string.h? In that case, yes it is possible. A string can be seen as an array of chars. Create a pointer which points to the string and let it run through the string until the end is reached. In this way you can count the number of characters.

    So you could do something like:

    Code:
    /* Let s be the string and i the number of characters */
    i = 0;
    while (s [i] != '\0')
    {
        i++;
    }

  6. #6
    Hamster without a wheel iain's Avatar
    Join Date
    Aug 2001
    Posts
    1,385
    remember the (assuming 8 bit) byte construction
    128|64|32|16|8|4|2
    read in a string , parse the string (check what is in each array element) if its not a 1 or a zero report an error
    then add the appropriate numbers together.
    Monday - what a way to spend a seventh of your life

  7. #7
    Registered User
    Join Date
    Mar 2002
    Posts
    4
    Thanks again.
    Sorry for making things complicated. But i'm glad that you still understand what I'm trying to say.

    frankly speaking, i am not quite fluent in term of written english.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21