Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning ASP.NET 4.5 Databases

Authors: Sandeep Chanda, Damien Foggon

3rd Edition

1430243805, 978-1430243809

More Books

Students also viewed these Databases questions

Question

Discuss recent trends in location and possible future strategies.

Answered: 1 week ago

Question

Prove property (5). u x (v + w) = (u X v) + (u X w) (5)

Answered: 1 week ago

Question

Compare value orientations among cultures

Answered: 1 week ago