Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For the questions below assume that N is an integer variable that occupies two o

ID: 3832380 • Letter: F

Question

For the questions below assume that N is an integer variable that occupies two or more bytes of memory (the exact number of bytes is unknown, so your solution should work for any number of bytes.) You may not use conditionals (if statements) or loops in your answers.

a) Write a single C statement that sets to 1 the sign (most significant) bit of N, leaving the remaining bits unchanged. You may use the sizeof operator in your answer.

b) Write a single C statement that clears (sets to zero) the least significant 4 bits of N, leaving the remaining bits unchanged.

c) Write a single C statement that sets to one bits 7, 9 and 11 of N, leaving the remaining bits unchanged. (Bit 0 is the least significant bit.)

Explanation / Answer

a) int x = 1<<((sizeof(int)*8)-1);

b) This will set initial 4 low bits to 0.

((n & ~(1<<0)) & (~(1<<1)) & (~(1<<2)) & (~(1<<3)))

c) (n | (1<<6)) | (1<<8) | (1<<10)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote