Directions: how do i write a c++ program that will convert from decimal to binar
ID: 3562750 • Letter: D
Question
Directions:
how do i write a c++ program that will convert from decimal to binary all the way up on hexadecimal?
A converter from one number system to another. Your program will ask base, target number system and value in base number system from the user. You will then perform the conversion and print the final result in target number system. You can assume that the largest base and target number system will be Hexadecimal number system. However, your implementation needs to generic and should be able to perform any conversions from binary to hexadecimal system. Note that your application needs to take possible incorrect entries into consideration and graciously handles those cases.
EXAMPLEs:
Example Execution 1:
Enter the base number system: 2
Enter the target number system: 16
Enter the value in base: 1110110011
The 1110110011 in base 2 is equal to 3B3 in base 16.
Example Execution 2:
Enter the base number system: 8
Enter the target number system: 2
Enter the value in base: 341109
Your entry is incorrect Enter the number again: 341105
The 341105 in base 8 is equal to 11100001001000101 in base 2.
Explanation / Answer
#include #include using namespace std; int a1, a2, remainder; int tab = 0; int maxtab = 0; int table[0]; int main() { system("clear"); cout > a1; a2 = a1; while (a1!=0) remainder = a1%2; a1 = a1/2; maxtab++; } maxtab--; a1 = a2; table[0] = table[maxtab]; while (a1!=0) { remainder = a1%2; a1 = a1/2; table[tab] = remainder; tab++; //tab } tab--; cout =0) / { coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.