Question

C++ DESIGN and IMPLEMENT a PROGRAM THAT WILL CONVERT A DECIMAL NUMBER to its HEXIDECIMAL VALUE....

C++

DESIGN and IMPLEMENT a PROGRAM THAT WILL CONVERT A DECIMAL NUMBER to its HEXIDECIMAL VALUE.

USE RECURSION TO ACCOMPLISH THIS.

OUTPUT: The Original Number and its HEXIDECIMAL EQUIVALENT.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>
#include <string>
using namespace std;

string decimal_to_hexadecimal(int number) {
    string s;
    int d;
    char ch;
    if (number > 0) {
        s = decimal_to_hexadecimal(number/16);
        d = number % 16;
        if (d < 10) {
            ch = (char)(d+'0');
        } else {
            ch = (char)('A'+(d-10));
        }
        s += ch;
    }
    return s;
}

int main() {
    int number;
    cout << "Enter a decimal number: ";
    cin >> number;
    cout << number << " in hexadecimal is " << decimal_to_hexadecimal(number) << endl;
    return 0;
}

Add a comment
Know the answer?
Add Answer to:
C++ DESIGN and IMPLEMENT a PROGRAM THAT WILL CONVERT A DECIMAL NUMBER to its HEXIDECIMAL VALUE....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Description For this program, you are going to convert decimal (integer) numbers into their octal number...

    Description For this program, you are going to convert decimal (integer) numbers into their octal number (integer) equivalents. Make sure that you create a new Project and Java class file for this assignment. Your Repl.It file should be named “Main.java”. You can read about octal-to-decimal number conversions from wikepedia or another website Instructions The input to the program will be a single non-negative integer number. If the number is less than or equal to 2097151, convert the number to its...

  • [Using Python] Write a program to convert a hexadecimal number to its decimal value. (Reminder: hexadecimal...

    [Using Python] Write a program to convert a hexadecimal number to its decimal value. (Reminder: hexadecimal numbers are 0 through 9, A,B,C,D,E,F. hex(A) = 10, hex(F) = 15). example outputs: 1. `Enter a hex number: f` `The decimal value for hex number f is 15` 2. `Enter a hex number: g` `Incorrect hex number` 3. `Enter a hex number: 091c` `The decimal value for hex number 091c is 2332` 4. `Enter a hex number: 091g` `Incorrect hex number` Hints: you...

  • a) The following program is supposed to convert a binary number to its decimal equivalent. Modify...

    a) The following program is supposed to convert a binary number to its decimal equivalent. Modify the program so that it does the job.(15 points) b) How would you create the executable file of the program (file name: b2d.c) in Linux? (5 points) #include <stdio.h> int main (void) int binary: printf("Enter a binary number:\n"); scanf("%d", &binary): int nofDigit = 0, remain = binary: while (remain > 0) - remain = remain/10; nofDigit++; int digit, dval = 0, bx = binary:...

  • c++ the program must use a stack to convert the decimal number to the numeric format....

    c++ the program must use a stack to convert the decimal number to the numeric format. Write a program that reads a string consisting of a positive integer or a positive decimal number and converts the number to the numeric format. If the string consists of a decimal number, Expert Answer

  • Write a VBA code to convert an arbitrary binary integer number to its equivalent decimal number....

    Write a VBA code to convert an arbitrary binary integer number to its equivalent decimal number. Specific requirements: Use InputBox function to acquire the input for an arbitrary binary integer number; Convert the binary integer to its equivalent decimal number; Return the decimal number in a message box. Submit your (VBA code) Excel screen shoot. Below functions may be useful in your VBA code: Val( ): can convert a string-type number in ( ) to its numeric value; Len( ):...

  • C++ Convert a Number from Binary to Decimal using a stack: The language of a computer...

    C++ Convert a Number from Binary to Decimal using a stack: The language of a computer is a sequence of Os and 1s. The numbering system we use is called the decimal system, or base 10 system. The numbering system that the computer uses is called the binary system, or base 2 system. The purpose of this exercise is to write a function to convert a string representing a binary number from base 2 to base 10. To convert a...

  • C++ programing (Visual Studio) Write a program to convert a Decimal number of any value inputted...

    C++ programing (Visual Studio) Write a program to convert a Decimal number of any value inputted by the user to a Type_4 number. Type_4 definitions: This number just have 4 digits: 0,1, 2, 3 Example: Decimal: 15 25/4 = 6 6/4 = 1 1/4 = 0 25% 4 = 1 6% 4 = 2 1% 4 = 1 Type_4 = 121

  • implement two functions in c++ format 1.Convert decimal number to floating point representation (hexa decimal) 2.Convert...

    implement two functions in c++ format 1.Convert decimal number to floating point representation (hexa decimal) 2.Convert floating point representation (hexa decimal) to decimal number Note: We only care about the floating point number in IEEE754 Encoding table below (i.e., exponent 1 – 254).   ----------------------------------------------------------------------------------------------------------------- void from_decimal_to_floating(){ char number[10]; float decimal = 0; cout << "Input decimal to convert a hexa decimal number (e.g., 0.4375): "; cin >> decimal; //write the code here //end of code cout << decimal << "'s...

  • Convert a decimal fractional number 34/5 to its binary equivalent using a program to  evaluate the bits...

    Convert a decimal fractional number 34/5 to its binary equivalent using a program to  evaluate the bits of the fractional part for at least upto the second repeating block. i have written some code in python however it is not getting an output at all, so either fixing the code or writing another one would be beyond helpful def binary(n,k): n = 8.6 k = 3 #'n' is the fractional number #'k' is the number of bits up to the loop...

  • Write a Java program to convert octal (integer) numbers into their decimal number equivalents (exactly the...

    Write a Java program to convert octal (integer) numbers into their decimal number equivalents (exactly the opposite of what you have done in Assignment 4). Make sure that you create a new Project and Java class file for this assignment. Your file should be named “Main.java”. You can read about octal-to-decimal number conversions on wikepedia Assignment 4 is at the bottom Objective Your program should prompt the user to enter a number of no greater than 8 digits. If the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT