Find first and last set bit of a long integer: Difference between revisions

Content deleted Content added
Rdm (talk | contribs)
J: define the words that were asked for
Rdm (talk | contribs)
Make the task definition be meaningful
Line 2: Line 2:
Define routines (or operators) '''lwb''' and '''upb''' that find the ''first'' and ''last'' set bit in a binary value. Implement using a binary search to find the location of the particular upper/lower bit.
Define routines (or operators) '''lwb''' and '''upb''' that find the ''first'' and ''last'' set bit in a binary value. Implement using a binary search to find the location of the particular upper/lower bit.


Also: Define the reverse routines (or operators) '''rlwb''' and '''rupb''' that find host's ''integers'' least- and most-significant set bit in a binary value expressed in [[wp:Bit_numbering#LSB_0_bit_numbering|LSB 0 bit numbering]], i.e. indexed from the extreme right bit.
Also: Define the reverse routines (or operators) '''rlwb''' and '''rupb''' that find host's ''positive integers'' least- and most-significant set bit in a binary value expressed in [[wp:Bit_numbering#LSB_0_bit_numbering|LSB 0 bit numbering]], i.e. indexed from the extreme right bit.


Use primarily '''bit''' operations, such as '''and''', '''or''', and bit shifting. Avoid additions, multiplications and especially avoid divisions.
Use primarily '''bit''' operations, such as '''and''', '''or''', and bit shifting. Avoid additions, multiplications and especially avoid divisions.