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

Do you mean clr on a single bit? ie. do you mean 'unset' (or zero) it?, or do you mean the entire byte? I can definitely add that for completeness, but as soonix stated, $data = 0; will do it too.

Replies are listed 'Best First'.
Re^3: Bit string manipulation made easy with Bit::Manip
by pryrt (Abbot) on Jan 30, 2017 at 20:17 UTC

    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).

      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";