in reply to Re: Handling bits in Perl
in thread Handling bits in Perl
One nice thing about the bitwise operators in Perl is that you can use them on whole strings, not just on integers. For example,
This outputs $z = ABCDEFGHIJKLMNOPQRSTUVWXYZ. (This is just an example, not recommended for case conversion because it screws up non-alphabetic characters.)use strict; my $x = "abcdefghijklmnopqrstuvwxyz"; my $y = ("A" ^ "a") x length($x); my $z = $x & ~$y; print "\$z = $z\n";
You should also be aware of pack/unpack "H*", pack/unpack "B*", or "b*, to print bit strings for debugging, to input long constants, etc.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Handling bits in Perl
by ikegami (Patriarch) on Jul 25, 2006 at 15:35 UTC | |
by Thelonius (Priest) on Jul 26, 2006 at 12:33 UTC |