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 what is wrong with this statement? Myname = ?robin?;

1520


Which control loop is recommended if you have to execute set of statements for fixed number of times?

1297


how to find anagram without using string functions using only loops in c programming

3129


List a few unconditional control statement in c.

924


What is #pragma statements?

1050


main() { int i = 10; printf(" %d %d %d ", ++i, i++, ++i); }

1087


Stimulate calculator using Switch-case-default statement for two numbers

2920


What is the size of a union variable?

996


write a program to rearrange the array such way that all even elements should come first and next come odd

2219


how can I convert a string to a number?

1026


Discuss the function of conditional operator, size of operator and comma operator with examples.

1093


Is main is a keyword in c?

1068


How do you initialize pointer variables?

1029


Implement bit Array in C.

1094


Is using exit() the same as using return?

1245