| | |
I dont know what mistake I did
![]() |
•
•
Join Date: Oct 2006
Posts: 2
Reputation:
Solved Threads: 0
converting binary numbers entered by the user to their equivalent decimal,program will have one function that takes an integer(1 and 0) upto 10 digits in length.Means binary into decimal ,I dont know where iam doing mistake, and my out put if i entered binary no 111 or any bin it gives 0 so plz help me where is the problem.prototype function should look like this:
int binconvert (int binNum);
int main ()
{
int foo;
cout<<"enter number:";
cin>>foo;
cout<<biconvert(foo)<< ":"<<foo<<endl;
return0;
}
int binconvert (intNum)
{
long int n,i=1,d=0,m=0,l=0;
while(n>0)
{
m=(n%10);
n=(n/10);
l=m*i;
d=d+l;
i=i*2;
}
return d;
}
You might reconsider using an int as your parameter type. You're limited to 10 binary digits, which leaves you with binary values from 0 - 1023 decimal (at least on my system). If that's fine for your needs, then so be it; otherwise you might consider using a long or using a string and parsing each character as a '0' or '1'.
![]() |
Similar Threads
- 100% CPU USAGE on and off! ;/ (Windows NT / 2000 / XP)
- What are vectors? (C++)
- i dont know anything about C++ need sum help!!! (C++)
- Is My New Ram Compatable??? (Motherboards, CPUs and RAM)
- lost xp cd please someone help (Windows NT / 2000 / XP)
- Bookmarker.gen can't get rid of! (Viruses, Spyware and other Nasties)
- Outlook Takes A Few Minutes To Open (Windows NT / 2000 / XP)
- OVER CLOCKING/OVER HEATING (Motherboards, CPUs and RAM)
Other Threads in the C++ Forum
- Previous Thread: Out Of Memory Problem
- Next Thread: Weird Stuff about Dev-C++ Compiler
| Thread Tools | Search this Thread |
ace_thread api array assignment based binary bitmap borland c++ c++endcode c/c++ char class classes code coding compile connect console conversion count delete delete-line deploy desktop developer directshow dll download dynamic dynamiccharacterarray email embedded encryption error file forms fstream function functions game givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream information input int integer java lib linkedlist linker loop looping loops map math mathhomeworkhelp matrix memory multidimensional multiple news node output pointer problem program programming project python random read recursion reference remote reverse richedit rpg string strings temperature template test text text-file tree url variable vector video win32 windows winsock wordfrequency wxwidgets






