binary to decimal problem

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2007
Posts: 22
Reputation: jimwalther is an unknown quantity at this point 
Solved Threads: 0
jimwalther's Avatar
jimwalther jimwalther is offline Offline
Newbie Poster

binary to decimal problem

 
0
  #1
Sep 29th, 2007
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;
}
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,342
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 237
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: binary to decimal problem

 
0
  #2
Sep 29th, 2007
Quick look -- perhaps:
  1. while (nextDigit == 1 || nextDigit ==0)
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC