While looking at the documentation to bit_set() to make sure my "not really necessary" was true, I had some thoughts:

Instead of calling the argument for the number of bits "$bits", I'd be tempted to document it as "$nbits"; some might want to misinterpret that argument name as a bit-mask instead of a number of bits, despite the text on the next line. (ie, when I first saw that, my mind set the "need more information flag" until I got to the next line. (This will especially help clarify if you end up implementing the next suggestion.)

With longer words, there have been times when I want to address multiple disjoint bits simultaneously, such as when a hardware designer separates bits that would logically be grouped. For example, suppose you had a register where in the cheap version of a part, you set a 4bit offset and an offset-enable, where the enable is in bit 4, and the 4 bit offset is bits[3:0] = offset[3:0]; but in a more expensive but pin-and-register compatible version, the same register has an additional 2 bits of offset above the sign bit, so it's bits[6:5] = offset[5:4], bits[4] = enable, bits[3:0] = offset[3:0]. (I design tests for hardware for a living; I've seen much more convoluted register words than that.) To that end, I would want

(I don't particularly like the _disjoint() naming convention... you might want to see if you can come up with a better one.)


In reply to Re: Bit string manipulation made easy with Bit::Manip by pryrt
in thread Bit string manipulation made easy with Bit::Manip by stevieb

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.