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
I / a / caught / when / was / on / disease / holiday / I​
statuscvo [17]

Answer:

Ig it'd be - I caught a disease when i was on a holiday.

4 0
3 years ago
Read 2 more answers
"In spreadsheet programs, labels and constant values are always copied exactly to the new location; what happens to formulas whe
Alex17521 [72]

Answer: Absolute cell referencing

Explanation:

 The absolute cell referencing is one of the type of cell reference address that basically contain the dollar sign in the spreadsheet applications. It is one of the important element as it helps in referring the constant values in the spreadsheet programs.

  • The absolute cell referencing is copied and also moved from one cell to another in the new location.
  • The size and also the shape are also remain constant in the spreadsheet.

According to the given question, the absolute cell referencing is also known as the relative cell referencing as they use the formulas for copied the values in the microsoft office excel for find out the data.

 Therefore, Absolute cell referencing is the correct answer.

8 0
2 years ago
The most important assistance that a full-featured HTML editor provides is _____.
Talja [164]
I would say code completion. Dreamweaver does this for you. So say I wanted to make a paragraph of text, I would use <p>, and then Dreamweaver would create the closing </p> for you.
4 0
3 years ago
kara, darrell and jose all enjoy watching comedies online. kara and jose also enjoy watching dramas. using content-based filteri
vitfil [10]

Answer:

thrillers?

Explanation:

my best estimation would most likely be a thriller...

4 0
3 years ago
Write a method rearrange that takes a queue of integers as a parameter and rearranges the order of the values so that all of the
Ksju [112]

Answer:

i got the answer

Explanation:

hope you can too

6 0
2 years ago
Other questions:
  • a) What are the 'interrupts' in a computer system? Describe the approaches to deal with multiple interrupts in a system.b) Analy
    12·1 answer
  • Describe an ergonomic consideration for your body while working for long periods in front of a monitor or computer screen?
    14·1 answer
  • Motorcycles have two or three wheels, a seat for the rider and at least a ____ horse-powered engine.
    15·1 answer
  • Renee's creating a plan for her business's information system. What should she do after she determines the goals for her busines
    10·1 answer
  • Describe the differences between program development and program execution, including the installed software required for develo
    5·1 answer
  • What is the different between ethical and legal issues?​
    6·1 answer
  • What is the fullform of ETA in computer term​
    15·1 answer
  • Your project will require a 7-day work week rather than the traditional 5-day. How can you adapt the software to this new schedu
    15·1 answer
  • Why doesn't brainly give me 15 questions a day
    11·2 answers
  • Susan is a network monitoring technician working on a firewall for her company’s network. In the process to determine an open po
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!