I prototype a lot of my C microcontroller code in Perl, and for that purpose so I, and others might benefit, I wrote Bit::Manip. That contains code that has to be compiled, so for a Pure Perl version, there's Bit::Manip::PP.
It does all the things that we who have to do bitwise operations from time-to-time but not as a profession (or often enough to remember how) we need to do.
Here's an example of turning 'off' a bit:
Code:
use strict; use warnings; use Bit::Manip qw(:all); my $num = 0b11100111; # or literal 231 my $bit_position = 6; my $flipped = bit_off($num, $bit_position); printf("orig: %b\n", $num); printf("flipped: %b\n", $flipped);
Output:
steve@maezi ~/scratch >perl bit.pl orig: 11100111 flipped: 10100111
In reply to Re: How can I set a bit to 0 ?
by stevieb
in thread How can I set a bit to 0 ?
by bartender1382
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |