in reply to reliable get position of leftmost bit in large integers

To check whether the most significant bit positions of two unsigned integer values are equal (or both are zero), this works for me:
sub msb_pos_is_equal { my ($x, $y) = @_; ($x ^ $y) <= ($x & $y) }
Update: Added the words "unsigned integer" in the first paragraph.

Replies are listed 'Best First'.
Re^2: reliable get position of leftmost bit in large integers
by wollmers (Scribe) on Mar 12, 2015 at 14:41 UTC

    Thanks. This smells very fast. I still need the value of the position, but only in case of a match, and only from one side. Then BrowserUK's solution should do it.

    WOW, maybe we can beat the speed of Algorithm::Diff::XS in pure Perl. Still reached 80% yesterday.

    Helmut Wollmersdorfer

Re^2: reliable get position of leftmost bit in large integers
by BrowserUk (Patriarch) on Mar 12, 2015 at 14:29 UTC

    Nice! ++