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
How to make a sad face on keyboard using alt?
forsale [732]
Literally just do a colon and parenthesis :(

:( :-(
8 0
4 years ago
Read 2 more answers
The blue section of the following Venn diagram could represent which of the following Boolean statements?
Rzqust [24]

Answer:

Last option: <em>Not </em>statement

Explanation:

Anything outside the borders of the circles are considered the <em>not</em> Boolean statement since the circles represent <em>or</em> and the overlap represents <em>and</em>.

Hope this helps :)

3 0
3 years ago
What is the function of a computer screen?
Leni [432]

Hi!

A computer screen is what you are staring at right now!

It displays the output. Behind it are wires and cords.



~CoCo

7 0
3 years ago
What will you see on the next line?
laila [671]

Answer:

[5, 10, 6, 32]

Explanation:

What myList.remove(6) will do is remove the first 6 it will encounter. It will cycle through the list like the following:

5 != 6 next element

6 = 6 remove

hope i helped :D

8 0
3 years ago
What to take for ptsd
REY [17]
Dank memes and medicine
6 0
4 years ago
Read 2 more answers
Other questions:
  • When reading data across the network (i.e. from a URL) in Python 3, what method must be used to convert it to the internal forma
    9·1 answer
  • Which statement correctly describes how the density and temperature of air is related .
    7·1 answer
  • Because the data was formatted the same in two inventory files, you decided to combine their contents into one file. Now you wan
    7·1 answer
  • If a triathlon is a sport combining three events, what do you think would be the word for a sport combining five events?
    7·1 answer
  • Need help ASAP??? Pick the best answers
    10·1 answer
  • Which of the following best describes the protocol used on the internet?
    8·1 answer
  • I need help with this question!!
    8·1 answer
  • Mary is working on joining of a new domain tree to an existing forest, but before starting the process, she should have at least
    7·1 answer
  • 1. What are the advantages and disadvantages of the digital darkroom as compared to a regular darkroom?
    15·1 answer
  • Is windows CUI operating system??<br><br><br>What is the main purpose of folder ????<br><br><br>​
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!