943,962 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2606
  • C++ RSS
Sep 29th, 2007
0

binary to decimal problem

Expand Post »
Hey guys, I'm having some trouble figuring out how to do a step in my program. My program is to convert binary numbers to interger values. Everything looks like it will work to me if I am able to add one more step. I have done calculations manually and it seems to work but I do not know how to take the first number out of the binary string then the second, third, etc. here is my program:

#include <stdlib.h>
#include <stdio.h>

int main ()
{

//prompt user for binary #

char binaryNumber;

printf("Please enter a binary number\n");
scanf("%c",&binaryNumber);
/*assign variable decimalValue 0*/
int decimalValue=0;


/*obtain variable nextDigit
(the first digit in the binary number, then the next and so on.)*/

here is where the problem is


while (nextDigit == (1||0))
{
/*assign variable decimalValue
the value of (decimalValue*2)+nextDigit*/
decimalValue = ((decimalValue*2) + nextDigit);
}

system("PAUSE");
return 0;
}
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jimwalther is offline Offline
22 posts
since Sep 2007
Sep 29th, 2007
0

Re: binary to decimal problem

Quick look -- perhaps:
C++ Syntax (Toggle Plain Text)
  1. while (nextDigit == 1 || nextDigit ==0)
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Initializing a member of a class with another const/destructor!
Next Thread in C++ Forum Timeline: C++ program telling if a number meets conditions





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC