JOIN
 Select a Forum     Round Tables New Member Discussions News Discussions Algorithm Matches Marathon Matches NASA Tournament Lab TopCoder Cookbook High School Matches Sponsor Discussions Development Forums Design Forums Search | Watch Thread  |  My Post History  |  My Watches  |  User Settings View: Flat (newest first)  | Threaded  | Tree Previous Thread  |  Next Thread Forums Tutorial Discussions A bit of fun: fun with bits To find the index of the lowest bit
 To find the index of the lowest bit | Reply "Extracting every last bitIn this section I'll consider the problems of finding the highest and lowest 1 bit in a number. These are basic operations for splitting a set into its elements. Finding the lowest set bit turns out to be surprisingly easy, with the right combination of bitwise and arithmetic operators. Suppose we wish to find the lowest set bit of x (which is known to be non-zero). If we subtract 1 from x then this bit is cleared, but all the other one bits in x remain set. Thus, x & ~(x - 1) consists of only the lowest set bit of x. However, this only tells us the bit value, not the index of the bit."If we take the lg of that value will we get the index?
 Re: To find the index of the lowest bit (response to post by nishantmc) | Reply The article is about efficient operations. In this case, converting a value to a double, calling a library routine and converting the result back to int is definitely less efficient.
 Forums Tutorial Discussions A bit of fun: fun with bits To find the index of the lowest bit Previous Thread  |  Next Thread