954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

binary to decimal problem

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
#include

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;
}

jimwalther
Newbie Poster
22 posts since Sep 2007
Reputation Points: 10
Solved Threads: 0
 

Quick look -- perhaps:

while (nextDigit == 1 || nextDigit ==0)
Dave Sinkula
long time no c
Team Colleague
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You