Problem

a) Show that this algorithm determines the number of 1 bits in the bit string S:procedure...

a) Show that this algorithm determines the number of 1 bits in the bit string S:

procedure bit count(S: bit string)

count := 0

while S ≠ 0

count := count + 1

S := S ˄ (S − 1)

return count {count is the number of 1s in S}

Here S − 1 is the bit string obtained by changing the rightmost 1 bit of S to a 0 and all the 0 bi Is to t he right of this to 1s. [Recall that S ˄ (S − 1) is the bitwise AND of S and S − 1.]


b) How many bitwise AND operations are needed to find the number of 1 bits in a string S using the algorithm in pan (a)?

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 3.3