Question

In: Computer Science

PLEASE SOLVE I WILL THUMBS UP AND RATE YOUR ANSWER WELL For the following two C...

PLEASE SOLVE I WILL THUMBS UP AND RATE YOUR ANSWER WELL

For the following two C functions:

int q1(int x) {

int m8 = 0x55;

int m16 = m8 | m8 << 8;

int m32 = m16 | m16 <<16;

int z = x | m32;

return !(~z);

}

int q2(int x) {

int m8 = 0x55;

int m16 = m8 | m8 << 8;

int m32 = m16 | m16 <<16;

int z = x & m32;

return !!z;

}

Part i) Explain what each function does without running the code. EXPLAIN YOUR ANSWER OR YOU WILL NOT RECEIVE CREDIT.

Part ii) For each of the above functions, write a simpler version of the function (if there is one)

Solutions

Expert Solution

So talking about first function q1 so it initializes m8 = 0x55

m8 = 00000000 01011000

m8 << 8 = 01011000 00000000 //shifts left by 8 times

now m16 = m8 | m8<<8 //Bitwise OR of m8 and m8<<8

that will be m16 = 01011000 01011000

similarly

m16 << 16 = 01011000 01011000 00000000 00000000

so m32 = m16 | m16 << 16

m32 =  01011000 01011000 01011000 01011000

now z = x | m32 // x is passed from argument is done Bitwise OR with m32

return !(~z) //so here basically '~' toggles every bit of z and '!' is not so atlast it return 0

now in function q2 m32 is similarly calculated as above

m32 =  01011000 01011000 01011000 01011000

now z = x & m32;

now x is done Bitwise AND with m32 stored in z

and return !!z not of not will be 1 if z is any number else than 0 if z is zero then not of not of 0 will be 0

now coming to your second question any simpler version i think this is simpler nothing complex


Related Solutions

PLEASE ANSWER I WILL RATE YOUR ANSWER AND THUMBS UP For the following C functions: int...
PLEASE ANSWER I WILL RATE YOUR ANSWER AND THUMBS UP For the following C functions: int q7(int x) {     return x & (~x+1); } int q8(int x, int m, int n) {     int a = ~m+1;     int b = ~x +1;     a = x + a;     b = b + n;     return !((a|b) >> 31); } int q9(int x, int n) {    /* assume x and n are not a negative integer */...
PLEASE SOLVE I WILL RATE AND THUMBS UP Assembly code question Write an LC3 program to...
PLEASE SOLVE I WILL RATE AND THUMBS UP Assembly code question Write an LC3 program to compute the XOR (exclusive OR) operation. The program computes the XOR of two numbers stored in registers R0 and R1 and returns the result in register R3. To test your program, before computing the XOR load the two values from memory locations x4000 (into R0) and x4001 (into R1).
Please solve all. I don't have any more questions left. I will give thumbs up. For...
Please solve all. I don't have any more questions left. I will give thumbs up. For Online Textbook Store & Payment System, please identify each of the requirements as a functional requirement/property or non-functional requirement/property. For every non-functional property/requirement, please add a remark to explain why. 10. The bookstore manager will be able to access the system in order to view sales summary reports. 11. Payments processed through the system are electronically transferred into the store’s bank account. 12. Bank...
Please answer all of the following for thumbs up: Explain the problem of intellectual property theft....
Please answer all of the following for thumbs up: Explain the problem of intellectual property theft. Next, address the reasonable and customary processes and procedures which should be used to discourage or make it difficult for employees, managers, and executives to inadvertently misuse and/or steal the company's intellectual property (at a minimum, you must address data classification and marking, separation of duties, and least privilege). You should also identify and explain five or more best practices which the company should...
This is for ethics. PLEASE DO NOT ANSWER IF YOU ARE NOT SURE. I WILL THUMBS...
This is for ethics. PLEASE DO NOT ANSWER IF YOU ARE NOT SURE. I WILL THUMBS DOWN IF INCORRECT. ANSWERS MUST BE CORRECT. T/F QUESTIONS PLEASE PROVIDE SOURCES. . The crime control paradigm of policing is most consistent with utilitarianism 7. One of the key principles of Packers crime control model is that repression of criminal behavior is more important than procedural justice. 8. The crime control model is consistent with the role of police officers as public servants.
Please answer following BOTH questions for THUMBS UP:- 1) Taking the Roman Coliseum as an example,...
Please answer following BOTH questions for THUMBS UP:- 1) Taking the Roman Coliseum as an example, describe how modern cost management accounting could be applied to a current attempt to recreate this structure. Be creative in your discussion. Add images to your answer. 2) How can budgeting be viewed as a choice process? Find a cartoon/comic strip image on the Internet to illustrate your discussion. Explain the relevance of this image to your answer. Find and use at least one...
Please type your answer, I will rate you well. This is about Threat Modeler when conducting...
Please type your answer, I will rate you well. This is about Threat Modeler when conducting risk assessments. What did you learn about threat modeling by examining the features of Threat Modeler? Should software like Threat Modeler be used exclusively, or in addition to other threat modeling techniques?
Please answer this question correctly and quickly for a thumbs up. In the Molly Anderson article...
Please answer this question correctly and quickly for a thumbs up. In the Molly Anderson article assigned for this class, Professor Anderson describes her food systems vision. Thinking about your own food systems vision, what are three things you would like to change or affect in the food system? Please respond by listing one thing you would like to do individually, one thing you would like society to do collectively, and one thing you think the UW could do to...
Thumbs Up Will Be Given For Answer. Chapter Topic: The Organization of IB Please find an...
Thumbs Up Will Be Given For Answer. Chapter Topic: The Organization of IB Please find an INTERNATIONAL BUSINESS article to use. By doing so, YOU NEED to please visit websites such as  Reuters, Bloomberg, Wall Street Journal, etc, and put in the keywords "International Business" and the chapter topic "The Organization of IB​​​​​​​" on the website. You NEED to choose a relevant and interesting article that was made within the PAST COUPLE MONTHS that has to do with "International Business" and...
Thumbs Up Will Be Given For Answer. Please ELABORATE and give examples on the 2 courses...
Thumbs Up Will Be Given For Answer. Please ELABORATE and give examples on the 2 courses of action/strategies Delta Airlines will take that are listed below: 1st course of action: Emphasize policies and protocols aligned with the CDC and WHO to ensure customer safety to retain brand loyalty (for aftermath of pandemic). Do this through advertising/marketing/consistent communication from CEO himself/offer benefits and reliable customer service. 2nd course of action: Shift their focus to other sources of revenue by undertaking a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT