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]
2 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]2 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
because of online writing, our audience: A. Compromise older people B. are bigger than before C. usually read less often D. are
lions [1.4K]
B. Are Bigger Than Before
8 0
3 years ago
Read 2 more answers
____________ reference is used when you want to use the same calculation across multiple rows or columns.
vlada-n [284]

Answer:

relative cell

Explanation:

So, if you want to repeat the same calculation across several columns or rows, you need to use relative cell references. For example, to multiply numbers in column A by 5, you enter this formula in B2: =A2*5. When copied from row 2 to row 3, the formula will change to =A3

7 0
3 years ago
Read 2 more answers
Four actions that can be implemented on a database to autocorrect violations of referential integrity, and the outcomes of the a
Paraphin [41]

Answer:

Follows are the matching to this question:

Option \ a \to \ Option \ 3\\\\Option \ b \to \ Option \ 4\\\\Option \ c \to \ Option \ 1\\\\Option \ d \to \ Option \ 2\\

Explanation:

While time-consuming or prone to errors mechanical adjustments to both the referential, databases could be configured with four measures to engine violations. The restricted action causes the insert, update, and removes to only be denied. Set Null to NULL sets the invalid external key, whereas Set Default to a specific core consideration specified in SQL sets a default foreign key. Its Cascade operation spreads the main changes in external keys.

6 0
3 years ago
How are people that have a lot of points and Brainliests still be only "Ambitious"? Here's an example:
Fiesta28 [93]

Answer:

some times brailny just a wile to update them selves due to all the people on it

Explanation:

5 0
2 years ago
Read 2 more answers
is a private connection of LANs and WANs that belongs to an organization, and is designed to be accessible only by the members a
Sedaia [141]

Answer:

Intranet.

Explanation:

The intranet will provide the sharing of information within the organization. It does not provide the accessibility of the network or the sharing of information outside the organization. The main advantage of the Intranet is to improve communication between the employees.

The intranet is a private connection of LAN and WAN which are belongs to an organization it means this network is authorized by the employee within organization not outside the organization .

7 0
2 years ago
Other questions:
  • Page orientation can be either landscape or _____.
    13·1 answer
  • Create a function (prob3_6) that will do the following: Input a positive scalar integer x. If x is odd, multiply it by 3 and add
    15·1 answer
  • When was kale discovered?
    9·1 answer
  • The design of a blog refers to:
    10·1 answer
  • You are given the task of reading in n numbers and then printing them out in sorted order. Suppose you have access to a balanced
    12·1 answer
  • Choose the type of error described.
    12·1 answer
  • WAP to find area of circle​
    12·1 answer
  • What is a computer please tell me ​
    10·2 answers
  • Several small stores rent space within a larger shopping centre. The owners of the shopping centre have provided a physical netw
    15·1 answer
  • Hi everyone can anyone tell me how to align the photo the right in code.org
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!