I hope I'm not confused with youre update, but I think I may understand what you are asking. Say, for example, your bit flag is set to my $bit_flag = 0b101; #5. And, you need to find out if the given bit flag has a bit flipped within the list of qw( 1 2 4 8 ). If this is the case (and I apologize if I am still not understanding), you could:
#!/usr/bin/perl use strict; use warnings; my $bit_flag = 5; #0b101 my @bit_list = qw( 1 2 4 8 16 ); # Assuming you want to test for truth of my above statment # later in the application, binary 1/0 will work fine my $bit_flipped = ( grep{ $bit_flag & $_ } @bit_list ) ? 1 : 0; # Continue on with the application
Runing a bitwise and will simply tell you that there are some bits that are up in both the $bit_flat as within one of the values in the @bit_list.

CPAN has a good resource that might better explain what I am trying to say, while detailing the differences between the bitwise and (&) and the bitwise or (|).

Again, I hope I am understanding your question well enough to answer it. Good luck!

---hA||ta----
print$_ for(map{chr($_)}split(/\s+/,join(/\B?:\w+[^\s+]/,<DATA>))); __DATA__ 67 111 100 101 32 80 101 114 108

In reply to Re: Flipping bits and using flags by wazzuteke
in thread Flipping bits and using flags by BMaximus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.