Question

In the base conversion problem, the task to be performed is to convert the number of base n to decimal. The base of number ca

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
#include <string>
using namespace std;

int main()
{
char str[10] ;
char base[1];
int b;
int p = 1;
int dec = 0;
int i;
// accept value and base
cout<<"\nEnter Number :: ";
cin>>str;
cout<<"\nEnter base :: ";
cin>>base;
// checkbase to make A as 10 B as 11
if(isdigit(base[0])==true)
b=atoi(base);
else
b=int(base[0])-65+10;
  
int len;
for(len=0;str[len]!='\0';len++);

int s;
// conversion
  
for (i = len - 1; i >= 0; i--)
{
if(isdigit(str[i])==true)
s=int(str[i])-'0';
else
s=int(str[i])-65+10;
  
dec += s * p;
p = p * b;
}
  
cout<<"\nDecimal of number "<<str<<" is :: "<<dec;
return 0;
}

Output

Enter Number:: 11A Enter base:: 16 Decimal of number 11A is :: 282

Add a comment
Know the answer?
Add Answer to:
In the base conversion problem, the task to be performed is to convert the number of base n to decimal. The base of num...
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
  • IN PYTHON! Radix Conversion(*UP TO BASE 37*) Constraints: • Use only basic arithmetic and comparison operations....

    IN PYTHON! Radix Conversion(*UP TO BASE 37*) Constraints: • Use only basic arithmetic and comparison operations. Do not make any function calls other than the recursive call to convertBase Write a recursive function: convertBase(n,base) that will convert the non-negative decimal number n (type integer) to the specified base and return it as a string. Note that decimal values can be converted to a different number base by repeatedly dividing the residual quotient of n // base until it is zero,...

  • 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( ):...

  • Hi, I need to change the conversion where stack is into a class stack and add...

    Hi, I need to change the conversion where stack is into a class stack and add a template <class type> PROMPT: 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, the program must use a stack to convert the decimal number to the numeric format. #include #include #include #include #include using namespace std; double conversion(string); int...

  • 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...

  • 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...

  • Using Python In the decimal system (base 10), a natural number is represented as a sequence...

    Using Python In the decimal system (base 10), a natural number is represented as a sequence dndn?1 . . . d0 of (decimal) digits, each of which is in the range 0..9. The value of the number is d0 ×100 +d1 ×101 +···+ dn ×10n. Similarly, in the binary system (base 2), a natural number is represented as a sequence bnbn?1 · · · b0 of (binary) digits, each of which is 0 or 1. The value of the number...

  • 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...

  • plz do these questions EENG 370 Homework 01 1 Convert the decimal number 120 to binary...

    plz do these questions EENG 370 Homework 01 1 Convert the decimal number 120 to binary and hex 2. Convert the hex number ESH to decimal and binary 3. Convert the binary number 0111 1011 to decimal and hex. 4. Write the Truth Table for this Logic Circuit. What is it? An automobile Cruise Control System automates the speed of the car (using feedback) based on some input. Label each box, input and output (the same as we did in...

  • 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...

  • Octal numbers have a base of eight and the digits 0–7. Write the scripts octalToDecimal.py and...

    Octal numbers have a base of eight and the digits 0–7. Write the scripts octalToDecimal.py and decimalToOctal.py, which convert numbers between the octal and decimal representations of integers. These scripts use algorithms that are similar to those of the binaryToDecimal and decimalToBinary scripts developed in the Section: Strings and Number Systems. An example of octalToDecimal.py input and output is shown below: Enter a string of octal digits: 234 The integer value is 156 An example of decimalToOctal.py input and output...

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