Question: Write a function setbits(x,p,n,y) that returns x with the n bits that begin at position p set to the rightmost n bits of y, leaving

Write a function setbits(x,p,n,y) that returns x with the n bits that begin at position p set to the rightmost n bits of y, leaving the other bits unchanged.

Use the given code. Add the code needed forunsigned int setbits(unsigned x, int p, int n, unsigned y)

Code: Answer in C Language

#include

using namespace std;

unsigned int setbits(unsigned, int, int, unsigned); unsigned int setbits(unsigned x, int p, int n, unsigned y) {

//Add Code here

}

int main(void) { unsigned x = 0XF8FF; unsigned y = 0XF0A2; int p = 8; int n = 4;

printf("%x ", setbits(x, p, n, y)); return 0;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!