Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

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?

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2015-10-09 06:08 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (233 votes), past polls