binary to decimal

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

Join Date: Apr 2009
Posts: 22
Reputation: ankit894u is an unknown quantity at this point 
Solved Threads: 0
ankit894u ankit894u is offline Offline
Newbie Poster

binary to decimal

 
0
  #1
Apr 27th, 2009
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. void PrintError(fstream&, char, bool&);
  7. int Conversion(fstream&, char&, bool&);
  8.  
  9. int main()
  10. {
  11. fstream InFile;
  12. char Bit;
  13. int Decimal;
  14. bool BadBit = false;
  15.  
  16. //Open file to read
  17. InFile.open("f:\\Binary.txt",ios::in);
  18.  
  19. //Read the first bit of the number
  20. InFile.get(Bit);
  21.  
  22. //continue reading all numbers till the end of file
  23. while (!InFile.eof())
  24. {
  25. //call Conversion to convert binary to decimal
  26. Decimal = Conversion(InFile, Bit, BadBit);
  27.  
  28. //check if there is error
  29. if (BadBit)
  30. {
  31. //Print out error message
  32. PrintError(InFile, Bit, BadBit);
  33. }
  34. else
  35. //output the equivalent value of decimal
  36. cout<<" = " <<Decimal<<endl;
  37.  
  38. //read the next number
  39. InFile.get(Bit);
  40. }
  41.  
  42. InFile.close();
  43.  
  44. return 0;
  45. }
  46.  
  47. int Conversion(fstream& In, char& InBit, bool& Error)
  48. /* Pre: The stream is open for input.
  49.   InBit is 1 or 0.
  50. Error indicates the InBit is not One or Zero.
  51.   Post: return the conversion of binary to decimal.
  52.   Resets Error to true when encounter error.
  53. */
  54. {
  55.  
  56. }
  57.  
  58.  
  59. void PrintError(fstream& In, char BadOne, bool& Error)
  60. /* Pre: The stream is open for input.
  61.   BadOne is bad digit.
  62. Error indicates the BadOne is bad digit.
  63.   Post: Prints error message.
  64.   Resets Error to false means there is no error.
  65. */
  66.  
  67. {
  68.  
  69. }




hey guys can sum1 plsss do dis program for me.....trust me guys i have been doin it from 3 days but m not able to do it.......pls guys i have a submission tmr....thanks a lot
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 2,052
Reputation: serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light 
Solved Threads: 118
Featured Poster
serkan sendur serkan sendur is offline Offline
Postaholic

Re: binary to decimal

 
0
  #2
Apr 27th, 2009
Due to lack of freedom of speech, i no longer post on this website.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 22
Reputation: ankit894u is an unknown quantity at this point 
Solved Threads: 0
ankit894u ankit894u is offline Offline
Newbie Poster

Re: binary to decimal

 
0
  #3
Apr 27th, 2009
but its from decimal to binary....... n i really want sum1 to edit n work on d program i have given above....i really dont have time nor do i know how to do it....i tried as much as i could.....plsss sum1 edit my program n post it for me...

output should be as follows

1 = 1
10 = 2
11 = 3
12: Bad number!
10000 = 16
10101 = 21
13: Bad number!
end: Bad number!
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 2,052
Reputation: serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light serkan sendur is a glorious beacon of light 
Solved Threads: 118
Featured Poster
serkan sendur serkan sendur is offline Offline
Postaholic

Re: binary to decimal

 
0
  #4
Apr 27th, 2009
Beg to Narue, she may hear your voice..
Due to lack of freedom of speech, i no longer post on this website.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: binary to decimal

 
0
  #5
Apr 28th, 2009
Plz rd da rulz uv da forum, an da stickies at da top. Stop using baby talk, we are adults here. And we are not a free homework service.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
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