The ascii characters '1004' are not a "bitstring". They are the hex representation of an integer.

Try this:

#! perl -slw use strict; use constant FLAGS => { FLAG_DELETED => 0x0001, FLAG_DRAFT => 0x0002, FLAG_SEEN => 0x0004, FLAG_RECENT => 0x0008, FLAG_FLAGGED => 0x0010, FLAG_ANSWERED => 0x0020, FLAG_SAVED => 0x0040, FLAG_MDNSENT => 0x0080, FLAG_STTPENDING => 0x0100, FLAG_FAVOURITE => 0x0200, FLAG_NOTIFY => 0x0400, FLAG_STTPRESENT => 0x0800, FLAG_STTCOMPLETE => 0x1000, }; my( $text, $int ) = split '\.', <DATA>; chomp $int; $int = hex $int; printf "Flag '%s' (%u) %s set\n", $_, FLAGS->{ $_ }, $int & FLAGS->{ $_ } ? 'is' : 'is not' for keys %{ FLAGS() }; __DATA__ mymessage.1004

Outputs:

C:\test>1030559.pl Flag 'FLAG_RECENT' (8) is not set Flag 'FLAG_STTPRESENT' (2048) is not set Flag 'FLAG_STTPENDING' (256) is not set Flag 'FLAG_FAVOURITE' (512) is not set Flag 'FLAG_DELETED' (1) is not set Flag 'FLAG_NOTIFY' (1024) is not set Flag 'FLAG_DRAFT' (2) is not set Flag 'FLAG_FLAGGED' (16) is not set Flag 'FLAG_SEEN' (4) is set Flag 'FLAG_SAVED' (64) is not set Flag 'FLAG_ANSWERED' (32) is not set Flag 'FLAG_STTCOMPLETE' (4096) is set Flag 'FLAG_MDNSENT' (128) is not set

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re: How do I test if a bit has been set in a bitstring by BrowserUk
in thread How do I test if a bit has been set in a bitstring by willk1980

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.