the smallest calculation gets the first non-0 bit of your int. How it works?
Let n be the bit length of your int. The opposite of the number x (bit b n-1 ... b 0 ) is calculated so that when you add x to -x you get 2 p . Since your integer is only n-bit, the received bit is discarded and you get 0.
Now let b ' n-1 ... b' 0 be the binary representation of -x.
Since x + (- x) should be equal to 2 n when you encounter the first bit 1 x (for example, at position i), the associated bit -x will also be set to 1 and when you add a number, you will get a carry.
To get 2 n, this carry has to be distributed across all bits to the end of the bit sequence of your int. Thus, the -x bit at each j position with i <j <n follows the following properties:
b j + b ' j + 1 = 10 (binary)
Then from the above we can conclude that: b j = NOT (b ' j ) and, therefore, b j and b' j = 0
On the other hand, bits b ' j of -x located at position j such that 0 <= j <i are controlled by the following:
b j + b ' j = 0 or 10
Since all related b j are set to 0, the only option is b ' j = 0
So the only bit that is 1 in both x and -x is 1 in position i
In your example:
x = 001011001111000
-x = 110100110001000
In this way,
0.0.1.0.1.1.0.0.1.1.1.1.0.0.0
1.1.0.1.0.0.1.1.0.0.0.0.0.0 and
\ ====================== /
0.0.0.0.0.0.0.0.0.0.0.1.0.0.0
Then the ripple rotates each adjacent "1" after position I (bit I turned on) to 0, and the first next 0 bit to 1 (due to the spread of the transfer). That's why you ripple :
r (x) = 0.0.1.0.1.1.0.1.0.0.0.0.0.0.0.0
Ones is calculated as dividing the smallest (r (x)) by the smallest (x). Since the smallest (x) is an integer with only one bit set to 1 at position i, you have:
(smallest (r (x)) / smallest (x)) โ 1 = smallest (r (x)) โ (i + 1)
The resulting integer also has only one bit, equal to 1, for example, at index p, so the expression substract -1 for this value will give you integer units, such as:
For each j such that 0 <= j <p,
those j = 1
For each j for which p <= j <n,
those j = 0
Finally, the return value is an integer such that:
- The first subsequence of the 1-bit argument is 0.
- All 0-bits before the subsequence are set to 1.
- The first 0-bit after the subsequence is set to 1.
- The remaining bits remain unchanged.
Then I can not explain the rest, since I did not understand the sentence:
a set containing m as a member is obtained