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
how can f be used for both float and double arguments in printf? Are not they different types?
What kind of structure is a house?
Where in memory are my variables stored?
How is null defined in c?
If one class contains another class as a member, in what order are the two class constructors called a) Constructor for the member class is called first b) Constructor for the member class is called second c) Only one of the constructors is called d) all of the above
What is the difference between #include and #include 'file' ?
What library is sizeof in c?
What standard functions are available to manipulate strings?
What is c++ used for today?
Where are some collections of useful code fragments and examples?
How to set file pointer to beginning c?
Explain how do you use a pointer to a function?
What do you mean by dynamic memory allocation in c? What functions are used?
What do you mean by Recursion Function?
Are the variables argc and argv are always local to main?