Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: reliable get position of leftmost bit in large integers

by martin (Friar)
on Mar 12, 2015 at 13:39 UTC ( [id://1119791]=note: print w/replies, xml ) Need Help??


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! ++

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1119791]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-04-25 20:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found