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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!