I need to convert decimals to binary and binary to decimals using a 24 bit number conversion system. Help?
-
I have the source code but I have no idea how to continue. If someone could show me the code and maybe explain why it works that would be awesome!! I'm completely new to this and am having difficulties teaching myself. Here's the source code. I'm using Visual Studios 2010 if that makes any difference: #include "stdafx.h" #include "Number.h" #include <iostream> #include <string> using namespace std; void process_DTB() ; void process_BTD() ; void process_EXIT(); void menu() ; bool valid(string,int) ; bool valid(int,int) ; const int SIZE = 24 ; int _tmain(int argc, _TCHAR* argv[]) { cout << "\n\tWelcome to 24-bit Two's Complement Number Conversion System\n\n"; while(true) { menu(); } return 0; } void menu(){ int choice ; cout << "\tOptions :\n\t\t1:decimal to binary\n\t\t2:binary to decimal\n\t\t0:Quit\n" ; cout << "\n\tYour choice:" ; cin >> choice ; switch(choice) { case 1 : process_DTB(); break ; case 2 : process_BTD() ; break ; case 0 : process_EXIT() ; break; default: cout << "\n\t*** Invalid choice****\n" << endl ; } } void process_DTB() { int n ; cout << "\n\tEnter an integer value you wish to convert: " ; cin >> n ; if ( !valid(n,SIZE)) { cout << "\n\t *** invalid value .... overflow " << endl << endl ; return ; } Number num(n) ; cout << "\n\t " << n << " = " << num.get_bin() << endl << endl; } void process_BTD() { cout << "\n\tEnter a binary number you wish to convert: " ; string bin ; cin >> bin ; // add your code here } void process_EXIT() { cout << "\n ... You are exiting 24-bit Two's Complement Number Conversion System...\n Bye!\n" << endl ; exit(0) ; } bool valid(int n, int size) { // make sure the number is within the valid range if ( n >= power(2,size) || n < -power(2,size)) return false ; else return true ; } bool valid(string s, int size) { // validate the string s is indeed binary and of length less or equal to size // put your code here }
-
Answer:
Good homework question...
Batsmyma... at Yahoo! Answers Visit the source
Related Q & A:
- In Visual Studio 2012 or 2013, how can I register a DLL file on Windows 7 64-bit computer using a Custom Action command?Best solution by Stack Overflow
- I need to find the exact location of the factory amplifier in a 2004 Porsche Cayenne.Best solution by Yahoo! Answers
- How do i scan something? First time using a scaner and i dont think im doing it right. help. thanks?Best solution by Yahoo! Answers
- Do I need to know a lot of math and physics to obtain a private pilot's license?Best solution by Yahoo! Answers
- What do I need to convert my 2004 Nissan Altima into an SE-R model?? ONLY EXTERIOR WISE?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.