| | |
binary to decimal problem
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
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;
}
#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;
}
![]() |
Similar Threads
- Number System:Conversion from binary to decimal (C)
- binary to decimal in c++ code (C++)
- How do I Take in Hexidecimal input out put binary, decimal, and octal (Java)
- i need code for binary to decimal (it should be written in 'C') (C)
Other Threads in the C++ Forum
- Previous Thread: Initializing a member of a class with another const/destructor!
- Next Thread: C++ program telling if a number meets conditions
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock wordfrequency wxwidgets






