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

I am working on a computer systems puzzle that works with bit representations. I

ID: 3549441 • Letter: I

Question

I am working on a computer systems puzzle that works with bit representations. I am working with a function called copyLSB. The legal operations are !, ~, &, ^, |,  +, <<, >>.

from my understanding, the idea of the code is supposed to look somewhat like this:

the decimal value 5 has the bit pattern [0101], the LSB is 1.
The decimal value 6 has the bit pattern [0110] the LSB is 0.
The function is supposed to copy the LSB to all bits.
So copying 1 to all bits yields 0xFFFFFFFF and copying 0 to all bits yields 0x00000000.

here is what I got so far but I get an error:

int copyLSB(int x) {

int mask = 0xFF
return !!mask;

I am trying to somehow make all the bits, depending on the least significant bit, match the least significant bit. I supose I should probably shift it but I am confused as to how much I should shift. Do you have any ideas or suggestions?

Explanation / Answer

int copyLSB(int x) {

int lsb =x % 2;

if(lsb==1)

return lsb | x;

else

return lsb & x;

}




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