Wednesday 15 September 2010

bit manipulation - Bitwise operations, confused with expression used in "The C programming Language"(book) -


In the book, I'm reading to learn the "C programming language" in chapter 2.
The book is explaining the bitwork operation and there is a function that shows how many bits are in an integer.
The following functions are ...

  int bittoat (unsigned x) {int b; {If (x and amp; 01) {b ++}} return b for (b = 0; x! = 0; x>> gt; = 1); }   

Then we have been given a practice explaining this.
"In the supplemental number of two, X-1 removes the correct 1-bit in X & 1; why use this description to write a quick version of Bitcount.

The problem is that I really can not understand that "x & amp; = (X-1) "What will work? Can someone explain this to me? Or send me for a resource that can understand me better? I am trying to understand it, but I can not really do it Thanks for any help you can give.
If there is anything wrong in my question then this is my first post. Please help improve my questions.

In both X and X-1 The correct bit can not be set 1, because the binary system number ends in 0 and 1 optional - therefore X & (x -1) is guaranteed to be a number whose correct bit is set to 0 and only holds true If both words are true, what does Andrew W say to the confusion, here is a bitword used (which is each ADS individually)?

EDIT: Now, the motivation Tell me It is only a part of the answer because the basic problem shows that the equivalent 1-bit will be reset. As Andrew W has already answered in detail in the correct version, I am not going to repeat his interpretation here , But I answer them.

No comments:

Post a Comment