in reply to Re^2: Bit string manipulation made easy with Bit::Manip
in thread Bit string manipulation made easy with Bit::Manip

My thought was that James wanted _clr is to _set as _off is to _on... But that's not really necessary, since all you need to do is _set($data, $lsb, $bits, 0).

Replies are listed 'Best First'.
Re^4: Bit string manipulation made easy with Bit::Manip
by jmlynesjr (Deacon) on Jan 31, 2017 at 21:48 UTC

    Bingo!

    While not necessary, it seems that clr would complete the API. As an old assembly coder, I think in terms of setting, clearing and flipping/toggling bits.

    As a minor nit pick... Setting a bit "on" or "off" doesn't tell you if the hardware is turning a device "on" or "off". Depends on how the designer set up the hardware. Active high? Active low? Could be either.

    James

    There's never enough time to do it right, but always enough time to do it over...

      I have added in a new function, bit_clr(), which will clear a range of bits: bit_clr($int, $lsb, $nbits);. Here's a small sample of my test file. This functionality will be available in the next release. Thanks for the suggestion!

      Sample part of test file:

      is bit_bin(bit_clr(255, 0, 8)), '0', "255, 0, 8 ok"; is bit_bin(bit_clr(255, 0, 2)), '11111100', "255, 0, 2 ok"; is bit_bin(bit_clr(255, 0, 3)), '11111000', "255, 0, 3 ok"; is bit_bin(bit_clr(255, 0, 4)), '11110000', "255, 0, 4 ok"; is bit_bin(bit_clr(255, 3, 1)), '11110111', "255, 3, 1 ok"; is bit_bin(bit_clr(255, 3, 2)), '11100111', "255, 3, 2 ok"; is bit_bin(bit_clr(255, 3, 3)), '11000111', "255, 3, 3 ok"; is bit_bin(bit_clr(255, 7, 1)), '1111111', "255, 7, 1 ok";

        My work is done here! LOL

        James

        There's never enough time to do it right, but always enough time to do it over...