The OP didn't give any indication that $m0 was different than expected. Changing the value of $m0 doesn't seem appropriate. But if it is, there are two improvements you can make.


When doing bit arithmetic, most people prefer to use actual bit arithmetic instead of powers. Not only is it more intuitive to use operations that match one's mental model, your approach fails if a bit is already set. Replace

$val += 2 ** $_

with

$val |= 1 << $_

As evidenced by these posts, vec is quite weird, so it's surely best to avoid it if it doesn't offer a benefit.

my $vec; vec( $vec, 0, 16 ) = $val;

can be replaced with

my $vec = pack 'n', $val;

In reply to Re^2: Displaying bit-vectors with Most Significant Bits to the left? by ikegami
in thread Displaying bit-vectors with Most Significant Bits to the left? by LanX

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.