Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: having trouble unmasking a binary string

by hdb (Parson)
on Mar 28, 2013 at 08:42 UTC ( #1025900=note: print w/ replies, xml ) Need Help??


in reply to having trouble unmasking a binary string

Why do you need all this strange logic? This works fine I think:

my %SWITCH = ( CAT => 0b00001, DOG => 0b00010, HAMSTER => 0b00100, FERRIT => 0b01000, FISH => 0b10000); my $petInput = 2; my @PETS; for (keys %SWITCH) { if ($petInput & $SWITCH{$_}){push (@PETS, $_);} } foreach (@PETS){print $_."\n";}


Comment on Re: having trouble unmasking a binary string
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2014-08-22 06:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (148 votes), past polls