Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

Explain is it better to bitshift a value than to multiply by 2?

1204


What are identifiers in c?

1204


What is the difference between array and linked list in c?

1160


How can you find the exact size of a data type in c?

1005


What is a buffer in c?

1005


What are data structures in c and how to use them?

1172


What are the general description for loop statement and available loop types in c?

1129


Why is main function so important?

1107


PROGRAM TO WRITE CONTENTS OF 1 FILE IN REVERSE TO ANOTHER FILE,PROGRAM TO COPY 1 FILE TO ANOTHER BY SPECIFYING FILE NAMES AS COMMAND LINE

2026


a c code by using memory allocation for add ,multiply of sprase matrixes

2804


Do you know what are the properties of union in c?

1081


program for reversing a selected line word by word when multiple lines are given without using strrev

2480


What are the 5 elements of structure?

1082


Can I use base-2 constants (something like 0b101010)? Is there a printf format for binary?

1005


Why do we use stdio h and conio h?

1091