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

Answer Posted / intfail

all the above answers are wrong...
never use loops. immediate rejection

CopyBits(x, p, n, y)

First get n bits from pos p from Y

bitsFromy = y >> (p-n+1) & (~(~0<<n))

Now, get a mask such that we can 0 out bits in x at pos p and n bits to the right

startpos = p -n +1

create a mask from (startpos, p)
mask = (~0 << p - startpos +1)<<startpos | ~(~0 << startpos)

Now, 0 out the the bits in the locations (starpos, p) in x
and apply the bits extracted from y
x = (x & mask) | (bitsFromy << startpos)

that is all it takes.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Differentiate between static and dynamic modeling.

630


What does nil mean in c?

682


What are the application of c?

656


What are structures and unions? State differencves between them.

623


Describe explain how arrays can be passed to a user defined function

613






How do you use a pointer to a function?

646


What are bitwise shift operators in c programming?

652


Write a C program linear.c that creates a sequence of processes with a given length. By sequence it is meant that each created process has exactly one child. Let's look at some example outputs for the program. Here the entire process sequence consists of process 18181: Sara@dell:~/OSSS$ ./linear 1 Creating process sequence of length 1. 18181 begins the sequence. An example for a sequence of length three: Sara@dell:~/OSSS$ ./linear 3 Creating process sequence of length 3. 18233 begins the sequence. 18234 is child of 18233 18235 is child of 18234 ........ this is coad .... BUt i could not compleate it .....:( #include #include #include #include int main(int argc, char *argv[]) { int N; pid_t pid; int cont; if (argc != 2) { printf("Wrong number of command-line parameters!\n"); return 1; } N = atoi(argv[1]); printf("Creating process sequence of length %d.\n",N); printf("%d begins the sequence.\n",getpid()); /* What I have to do next ?????? */ }

1626


What is variable initialization and why is it important?

627


Write the test cases for checking a variable having value in range -10.0 to +10.0?

1831


Can we access the array using a pointer in c language?

567


Is that possible to store 32768 in an int data type variable?

700


What does p mean in physics?

595


What does struct node * mean?

610


What is the advantage of using #define to declare a constant?

629