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
ludmilkaskok [199]
3 years ago
11

3. Write a program that inputs 4 hexadecimal digits as strings (example 7F), converts the string digits to a long – use strtol(i

nput string,&ptr,base) to do the conversion. Just declare ptr as a char ptr, don’t worry about what it does. Copy each converted number [ a long] into unsigned char’s [like the variable num1 below – hint: cast a long variable into the unsigned char’s] before performing the following logical operations on them (parenthesis might help, since things should be executed from left to right): result=num1 and num2 or num 3 exclusive or num4 print out result in capital hex (15 points)
Computers and Technology
1 answer:
never [62]3 years ago
4 0

Answer:

#include <stdio.h>

#include <stdlib.h>

int main()

{

char num1[20],num2[20],num3[20],num4[20];

//Checks where the conversion of string to long stops and is required by strtol

char *ptr;

//Stores the converted number string into long.

long result_num1,result_num2,result_num3,result_num4;

//Prompt to enter all the four hexadecimal numbers.

printf("Enter the first hexadecimal number: ");

scanf("%s",num1);

printf("Enter the second hexadecimal number: ");

scanf("%s",num2);

printf("Enter the third hexadecimal number: ");

scanf("%s",num3);

printf("Enter the fourth hexadecimal number: ");

scanf("%s",num4);

//Converting the hexadecimal numbers into long using strtol() function with base 16 for hexadecimal.

result_num1 = strtol(num1,&ptr,16);

result_num2 = strtol(num2,&ptr,16);

result_num3 = strtol(num3,&ptr,16);

result_num4 = strtol(num4,&ptr,16);

//Casting the long to unsigned chars.

unsigned char numb1 = (unsigned char)result_num1;

unsigned char numb2 = (unsigned char)result_num2;

unsigned char numb3 = (unsigned char)result_num3;

unsigned char numb4 = (unsigned char)result_num4;

//Applying the boolean operation on unsigned chars and storing the resultant value in result.

unsigned char result = ((numb1&numb2)|numb3)^numb4;

//Printing the result in capital hex ("%X" take care of this).

printf("%X",result);

return 0;

}

Code OUTPUT

Enter the first hexadecimal number: 1 Enter the second hexadecimal number:2

Enter the third hexadecimal number: 3 Enter the fourth hexadecimal number: 4 Resultant Value: 7 Process returned o (0×0) execution time : 3.076 s

Press any key to continue

You might be interested in
What is the best overall approach to education and career development for IT professionals?
eduard
Formal education followed by lifelong learning i belive<span>
</span>
4 0
3 years ago
Read 2 more answers
What would happen if the coils in a generator stopped spinning?
just olya [345]
The generator will start to slow down and heat up.. because sooner or later the energy that is supposed to be going to the coils spinning then it all goes to heat.. The generator will either catch on fire or stop working completely. 
8 0
4 years ago
Read 2 more answers
Joe wants to use pictures from the internet in a word processing program which is the most important aspect that Joel should con
MrRa [10]
I would say B-copyright.
6 0
4 years ago
Read 2 more answers
Themes are applied from which tab?
Verdich [7]
Themes are selected in different tabs. It varies. 
3 0
3 years ago
Solve the equation w - 2 = -3<br><img src="https://tex.z-dn.net/?f=w%20%3D%20%20%20-%20%20%5Cfrac%7B3%7D%7B2%7D%20" id="TexFormu
Andreyy89
Heres my answer w= -1
4 0
3 years ago
Other questions:
  • Which of the following is an appropriale way to declinc an offer in a<br>professional environment?​
    13·2 answers
  • What is top down design? a. Top down design is a way of designing your program by starting with the biggest problem and breaking
    7·1 answer
  • How to delete the last element in array
    15·1 answer
  • Can you help me match the ships to the right number?​
    12·1 answer
  • Why do some people have random numbers as their usernames?
    9·2 answers
  • On what aspect of digital media do people often focus on at the expense of the important supporting roles?
    8·1 answer
  • CLI is not used friendly ​
    15·1 answer
  • Which of the following includes premium content you must pay to use?<br> On word
    6·1 answer
  • status is a non-volatile memory chip used for store translation data between personal computer PC and digital device ​
    8·1 answer
  • "using this type of communications channel, several users can simultaneously use a single connection for high-speed data transfe
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!