Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^2: Which bit is set? (inverse of (1<<$value) operator)

by wirito (Acolyte)
on Sep 17, 2012 at 12:11 UTC ( #994023=note: print w/ replies, xml ) Need Help??


in reply to Re: Which bit is set? (inverse of (1<<$value) operator)
in thread Which bit is set? (inverse of (1<<$value) operator)

Many thanks!

The lookup idea is nice and clean. I will use it as I only have 9 different bits.

However, your second option is the one I was (foolish) looking for. In my code, this could be the line:

# return the first less significant bit set. return $_ for grep { $bit & 1<<$_ } (0..8)';


Comment on Re^2: Which bit is set? (inverse of (1<<$value) operator)
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2015-09-01 22:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred temperature scale is:










    Results (50 votes), past polls