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
How works GPS on boats?
zaharov [31]
If you mean sonar it uses echolocation but GPS is signaled from satellite to the internal antenna
8 0
3 years ago
What do TCP/IP MEAN​
melomori [17]

Answer:IP is internet protocol, every router has one some routers are dynamic which means they change everything the router reboots and some routers are static which means you would have to call your isp(Internet Service Provider) to get it changed.

Explanation: I do illegal things :)

8 0
3 years ago
Digital Subscriber Line (DSL) is a way for traditional telephone companies to provide Internet access a way for traditional cabl
zvonat [6]

Answer:

Option A is correct

Digital Subscriber line is a way where telephone companies provide internet access for connection.

It is a communication medium used to transfer digital signals. DSL is one of the most popular broadband internet access.

Explanation:

DSL stands for Digital Subscriber Line. DSL works with high-speed bandwidth that connects from a phone jack to a telephone network. DSL works within frequencies. You can use the DSL while making phone calls.

6 0
3 years ago
Read 2 more answers
Which of these port transmits digital video
DaniilM [7]

Answer:

uhm

Explanation:

theres nothing there

7 0
3 years ago
Read 2 more answers
Which of the following statements is false?
mart [117]

Answer:

3 is true others are false

3 0
3 years ago
Read 2 more answers
Other questions:
  • A customer has a web server for a small business. The business uses both wired and wireless networking. A Linksys WRT300N wirele
    13·1 answer
  • When you are working on an unsaved document on a PC, where is the document temporarily saved?
    5·1 answer
  • A hard disk is divided into tracks which are further subdivided into:​
    11·1 answer
  • The shell that is used by default in linux is the _____ shell.
    12·1 answer
  • What statement best decribes the relashionship bewteen science and technoligy?
    11·2 answers
  • . Two or more functions may have the same name, as long as their _________ are different.
    9·1 answer
  • Is a psychrometer more likely used at a beach or a desert in California
    12·1 answer
  • Define power supply and types of power supply<br>​
    11·1 answer
  • Who Is faster sonic or flash well it all depends on which version of sonic your talking about like for example video game sonic,
    14·1 answer
  • Which option will be used to attach email messages ​
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!