Question
(Decimal to binary) Write a function that parses a decimal number into a binary number as a string. The function header is as follows: string
(Decimal to binary)
Write a function that parses a decimal number into a binary number as a string. The function header is as follows:
string dec2Bin(int value)
See Appendix D, Number Systems, for converting a decimal into a binary.
Write a test program that prompts the user to enter a decimal number and displays its equivalent binary value.
I have this so far:
#include
using namespace std;
string dec2Bin(int value) { int dec; cout << "Enter decimal number: "; cin >> dec; cout << "The binary equivalent is: " << dec2Bin(dec); { string bin = ""; int rem = 0; while (value != 0)
{ rem = value % 2; if (rem > 9)bin += rem + 55; else bin += rem + 48; value /= 2; } string binlnOrder = ""; for (int i = bin.length() - 1; i >= 0; i--) binlnOrder += bin[i];
return binlnOrder;
} return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started