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
Katyanochek1 [597]
3 years ago
8

Defining a hexadecimal number as in Problem 67, write the function int hexToDec( const int hexNum[]) to convert a four-digit hex

adecimal number to a nonnegative decimal integer. Do not output the decimal integer in the function. Test your function with interactive input.
Computers and Technology
1 answer:
lyudmila [28]3 years ago
3 0

Answer:

#include <stdio.h>

int hexToDec(const int hexNum[]){

   int result = 0, prod = 1;

   for(int i = 3;i>=0;i-=1){

       result += (prod*hexNum[i]);

       prod = prod * 16;

   }

   return result;

}

int main()

{

   int hexNum[4], i;

   char s[5], ch;

   printf("Enter hexa decimal value: ");

   scanf("%s",s);

   

   for(i = 0;i<4;i++){

       ch = s[i];

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

         hexNum[i] = ch-'0';

      }

      else if((ch>='a' && ch<='f') || (ch>='A' && ch<='F')){

         if(ch=='A' || ch=='a'){

            hexNum[i] = 10;

         }

         else if(ch=='B' || ch=='b'){

            hexNum[i] = 11;

         }

         else if(ch=='C' || ch=='c'){

            hexNum[i] = 12;

         }

         else if(ch=='D' || ch=='d'){

            hexNum[i] = 13;

         }

         else if(ch=='E' || ch=='e'){

            hexNum[i] = 14;

         }

         else{

            hexNum[i] = 15;

         }

      }

   }

   

   printf("%d",hexToDec(hexNum));

   return 0;

}

Explanation:

You might be interested in
What was a result of george washington's belief in the sovereignty of the people instead of monarchy?
Ilya [14]
<span>George Washington's belief in the sovereignty of the people instead of monarchy led him to reject a third term as president.</span>
8 0
3 years ago
What is the easiest way to be sure you have selected all of the content related to a specific tag?
pychu [463]
Add a <div> around it.
example:
<div id = "content">
<p> content</p>
</div>
4 0
3 years ago
Handhed computer is otherwise called as<br> 1.laptop<br> 2.Notebook<br> 3.Palmtop
NikAS [45]

Answer:

personal digital assistants (PDAs)palmtop

3 0
3 years ago
1. What is the central idea of the section "Service Record." Use two text details to
Vladimir [108]

Answer:

Service record is the record that is used to track the record of service of the employ in an organization.

Explanation:

The idea behind the service record is to maintain the whole detail of record of the person during his employment including, personnel information,  record related to his promotions and posting, salary record etc.

8 0
3 years ago
The windows troubleshooting utility that identifies and eliminates nonessential files is called _____.
Virty [35]
I think it is Defragment
8 0
3 years ago
Read 2 more answers
Other questions:
  • If r is an instance of the above Person class and oddNum has been declared as a variable of type boolean, which of the following
    8·1 answer
  • To configure a router / modem, what type of IP interface configuration should you apply to the computer you are using?
    8·1 answer
  • Which magazine can help the public to determine the best technology to buy?
    14·1 answer
  • Generally considered to be the most important information security policies, what item below defines the actions a user may perf
    11·1 answer
  • What is the difference between a software engineer and a system analyst?
    8·1 answer
  • When looking at a relationship between two tables on an ERD, the _____ table can be identified by the presence of a foreign key
    8·1 answer
  • When using file explorer, the right-hand pane that shows the files and folders of the selected area is called the pane?
    7·1 answer
  • Write a program that asks the user to enter two integer numbers X and Y. The program halves each number between X and Y then pri
    15·1 answer
  • Ten examples of an interpreter
    8·1 answer
  • Identify two real-world examples of problems whose solutions do scale well
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!