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 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 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...
What is better, BMW or Mercedes in your opinion? Thumbs up for every answer!
What is better, BMW or Mercedes in your opinion? Thumbs up for every answer!
PLEASE ANSWER WITH 200 WORDS OR MORE FOR A THUMBS UP RATING! THANK YOU! In 200...
PLEASE ANSWER WITH 200 WORDS OR MORE FOR A THUMBS UP RATING! THANK YOU! In 200 words or more, please explain why angel investments are important. *NOTICE* I do NOT need a definition of what angel investors are, I just need to know why angel investing is important
PLEASE ANSWER WITH 200 WORDS OR MORE FOR A THUMBS UP RATING! THANK YOU! In 200...
PLEASE ANSWER WITH 200 WORDS OR MORE FOR A THUMBS UP RATING! THANK YOU! In 200 words or more, list some examples of angel investment trends in the United States. *NOTICE* I do NOT need a definition of what angel investors are!
please leave alot of quality information and i will provide a thumbs up in return thank...
please leave alot of quality information and i will provide a thumbs up in return thank you 1. Joan is an Accountant who opposes the introduction of a new financial control system. For 15 years she has worked with a manual system. Now the firm is introducing a new computer-based system. How would you, as her manager, attempt to change Joan's attitude towards the new system? 2. Some people believe that perception is a more important explanation of behavior than...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT