1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
kow [346]
3 years ago
6

Implement function hex2dec that takes a hex number hex_num as a string argument and prints out the corresponding decimal number.

Each char in the string represents one of the 16 hex digits: '0', '1', '2', '3', ..., 'A', 'B', 'C', 'D', 'E', 'F'. No lower case letters will be used in the string. The string does not have any leading space nor the prefix "0x". For example, function call hex2dec("EF10") should print 61200. You can assume that hex_num can have up to 8 hex digits. To convert a char in the hex number string to an int, you need to check whether the char is in the range of '0' to '9'. If so, you can subtract the char by '0' to get its corresponding number. Otherwise, you need to subtract the char by 'A' and then add 10 to get its corresponding value. For example, you can use hex_num[0] - 'A' + 10 to get the int value for the most significant digit of the hex number, if the digit is between 'A' and 'F'. Restriction: printf is the ONLY C library function that you can use in the implementation.Restrictions:- printf is the ONLY C library function that you can use in the implementation (no scanf)- no pow() function - cannot add additional code to the int main() to test code - you can only call the function

Computers and Technology
1 answer:
DerKrebs [107]3 years ago
4 0

Answer:

Check the explanation

Explanation:

#include <iostream>

using namespace std;

void hex2dec(string hex_num){

int n = 0;

//Loop through all characters in string

for(int i=0;i<hex_num.size();i++){

//take ith character

char c = hex_num[i];

//Check if c is digit

if(c>='0' && c<='9'){

n = 16*n + (c-48);

}

//Convert c to decimal

else{

n = 16*n + (c-55);

}

}

cout<<hex_num<<" : "<<n<<endl;

}

int main()

{

hex2dec("EF10");

hex2dec("AA");

return 0;

}

The Output can be seen below :

You might be interested in
Write one DDL statement to add a new table Project into exam1. It contains the followingthree columns:-ProjNum of char(3) type,
Goryan [66]

Answer:

Check the explanation

Explanation:

When it comes to database management systems, a query is whichever command that is used in the retrieval of data from a table. In a Structured Query Language (SQL), generally queries are more or less always made by using the SELECT statement.

I have been trying to type it here but it's not working

so kindly check the code in the attached image below

8 0
3 years ago
Kathi, the owner of Klothes for Kats, is excited about the launch of her first Local Catalog ad. She remembers there are a few d
mina [271]

Answer:

Map view

Explanation:

The view that will most likely be displayed would be a Map view, where potential customers can see the Klothes for Kats logo, store information, and in-stock products. This is because Local Catalog ads only have a small space that is used to promote what is being advertised. Therefore, in these small spaces the most important things need to be shown in order to attract as many people as possible with what the store offers. The ad needs to have the logo and store information so that the potential customers can easily know what store is being advertised on the ad. The ad also needs to show some of the popular in-stock products in order to attract individuals that are actually interested in the products that the store is trying to sell.

6 0
3 years ago
What is the error in the following line: (1)<br><br> age=int(input("Enter your age:")
Ainat [17]

Answer:

14

Explanation:

6 0
3 years ago
Which term describes the process of training a machine to do simple, repetitive tasks, and adapt or correct its performance base
yKpoI14uk [10]
Automation. ... It involves taking a machine or software that was taught to do simple repetitive tasks (traditional automation) and teaching it to intuitively adapt or correct its performance based on changing conditions, at speed and scale.
8 0
3 years ago
URGENT PLEASE HELP!!!!!
Allisa [31]

Answer:

in my opinion I choose the rule of simplification

7 0
3 years ago
Other questions:
  • Which of the following devices electronically sorts mail by ZIP code? A. Fax modem B. Electronic organizer C. Optical character
    10·1 answer
  • Which one of the following downloads and uploads files to and from a server? A. Client B. Internet protocol C. Server D. Worksta
    9·1 answer
  • Jemima is reviewing her history report and notices that her headings are not formatted the same throughout the report. She wants
    5·2 answers
  • Working in a meat factory packaging and shipping the meat deliveries falls into which agricultural cluster?
    7·1 answer
  • Some loops are controlled by ____ (or reducing) a variable and testing whether the value remains greater than some benchmark val
    15·1 answer
  • Which of the following Web sites would be MOST credible?
    6·1 answer
  • What are the most positive and the most negative decimal numbers that can be represented by a 2C (n+k) bit fixed-point number, w
    12·1 answer
  • What is the google search operator that limits results to a specific domain?
    8·1 answer
  • How to use function in python
    15·1 answer
  • Outline 3 computer system problem that could harm people and propose the way avoid the problem​
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!