CopyBits(x,p,n,y)
copy n LSBs from y to x starting LSB at 'p'th position.

Answer Posted / angad

t=0;
for(i=n; i>0; i--)
{
t|=(1<<p);
p++;
}
x=x&~t
t=t&(y<<p);
x=x|t;
}

x=10100110
y=11110111
let,p=3,n=4

after for loop, t=01111000 - mask for the n(=4) bits starting from the p(=3) bit that need to be altered in x

x=x&~t;
x =10100110
~t=10000111
ANDing clears the 4 bits to zero(bits 3-6)
x=1 0000 111

we need to extract the 1st n(=4) bits out of y , and shift them left to align them against the n(=4) bits of x we need to alter, therefore, left shift y by p(=3)
t=t&(y<<p)

y<<p = 1 0111 000
t = 0 1111 000
AND=>t = 0 0111 000

now x = 1 0000 111
t = 0 0111 000

x=x|t =>1 0111 111

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is #line in c?

572


How can I do graphics in c?

603


How can a process change an environment variable in its caller?

664


explain what are pointers?

630


What is the meaning of typedef struct in c?

606






What is use of integral promotions in c?

673


Where register variables are stored in c?

560


What is the purpose of 'register' keyword in c language?

637


Without Computer networks, Computers will be half the use. Comment.

1883


Explain why can’t constant values be used to define an array’s initial size?

872


Explain about C function prototype?

617


Why & is used in c?

728


What is structure in c definition?

583


I have written a pro*C program to fetch data from the cursor. where in i have used the concept of BULK FETCH.... each FETCH statement is taking lots of time to fetch specified number of rows at...

9665


Do pointers need to be initialized?

575