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
Monero is cryptocurrency that focuses on transparency of ownership. True or false
dangina [55]

Answer:

TRUE

Explanation:

4 0
2 years ago
End users have complained that when they click a link on your company's Website, the wrong client loads. You review the page wit
Ilia_Sergeevich [38]

Answer:

4. A Web server has been specified.

Explanation:

End users have complained that when they click a link on your company's Website, the wrong client loads. You review the page with the suspect link and find the following HTML code:

To begin an FTP session, click the following link:

FTP Session

The problem is that Web server has been specified.

7 0
2 years ago
What type of game is LEAST LIKELY to need a structured narrative?
VladimirAG [237]

Answer:

Probably a sports game

Explanation:

A role-playing means acting it out, so you need to explain the life with a structured narrative.

An adventure game needs lots of background, so you need to fill that in with a structured narrative.

A sports game revolves solely around sports, so you only need to know how to play the game and/or sport, so no structured narrative is needed.

An fps game needs a structured narrative in that it is similar to an adventure game and needs background.

Let me know if I was right! Hope this helped. :)

5 0
3 years ago
Cyber security class i need help​
makkiz [27]

Answer:

Explanation:

yooooo it b

5 0
2 years ago
Date Time Manipulation Exploration If you start from Jan 1st, 1757, and repeatedly add 8 days, until you hit 1800, how many time
zimovet [89]

Answer:

from datetime import datetime, date, timedelta

def count_weekdays(start_date, add_days, stop_year, weekday):

   my_date = start_date

   m = 0  

   while my_date.year != stop_year:  

       my_date = my_date + timedelta(days = add_days)

       if my_date.isoweekday() == weekday:

           m += 1

   return m

date_val = date(1757,1,1)

try:

   date_val = datetime.fromisoformat(input("Enter date in the format yyyy-mm-dd: "))

except ValueError:

   print("Wrong isoformat string")

print(count_weekdays(date_val, 8, 1800, 1))

Explanation:

The datetime package of the python programming language has several time modules like the date, datetime, pytz, timedelta, etc, used to manipulate date and time in documents. The function count_weekdays has four parameters and returns the number of a specified weekday in a period of time.

4 0
3 years ago
Other questions:
  • A customer states that when she removes the printed pages from her laser printer output tray, the black ink smears all over her
    10·1 answer
  • John works for Internal Computer Specialists, which focuses on helping small business owners resolve MIS infrastructure issues.
    12·1 answer
  • Which osi layer is responsible for combining bits into bytes and bytes into frames?
    8·1 answer
  • Charles would like to move his internet browser window so that he can see his desktop.He should
    5·1 answer
  • ________________ occur when a system produces incorrect, inconsistent, or duplicate data.
    6·2 answers
  • Write a loop that inputs words until the user enters STOP. After each input, the program should number each entry and print in t
    12·1 answer
  • Which of the following is best known as a business network LinkedIn, Facebook, Twitter or Word Press?
    15·1 answer
  • In what way , if any, can your social media presence affect your chances of getting a job in social media?
    8·1 answer
  • What is problem scoping
    14·1 answer
  • Which workbook view is used most often in Excel?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!