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
Give two examples of non printing characters
VMariaS [17]
Space — each pressing of the key will be displayed as ·
Non-breaking space (°) is a space character that prevents an automatic line break at its position.
3 0
3 years ago
What was the importance of the turing machine to today’s computers?
Ronch [10]
It helps you with life and brainly
5 0
3 years ago
Discuss the relationship amongst the following basic file elements: • Field. • Record. • File. • Database. • Directory.​
Gwar [14]

Answer:

describe two events from the life of the prophet that illustrate the way he treated non muslims3+15-75+375.

Explanation:

53+15-75+3756,1803+15-75+375describe two events from the life of the prophet that illustrate the way he treated non muslims

4 0
1 year ago
This project involves writing a java program to simulate a blackjack card game. You will use a simple console-based user interfa
coldgirl [10]

Answer:i dont know sorry

Explanation:

8 0
3 years ago
Chang investigates ways to improve the interactivity of computer hardware. His job title is best described as ✓ Computer and Inf
xeze [42]

Answer:

B, D, C

Explanation:

got it right

3 0
2 years ago
Other questions:
  • What are the types of action involving data base?
    14·1 answer
  • Siva added a "Contact Form" to her website.
    10·1 answer
  • You coded the following class: public class N extends String, Integer { }When you compile, you get the following message:N.java:
    9·1 answer
  • Which of the following people was a member of FFA?
    7·1 answer
  • How can the function abcfunc change the address in its local copy of intpoint?
    11·1 answer
  • Which element appears within the top margin of the document but does not form the part of the body of the text?
    15·1 answer
  • When reading words using a Scanner object's next method, _________. a. any characters at the beginning of the input that are con
    5·1 answer
  • . Each ____ on a menu performs a specific action.
    14·1 answer
  • The purpose of Appetizers on the menu​
    6·2 answers
  • Complete the code to finish this program to analyze the inventory for a store that sells purses and backpacks. Each record is co
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!