Skip to content

Instantly share code, notes, and snippets.

@xtetsuji
Created July 30, 2013 09:23
Show Gist options
  • Select an option

  • Save xtetsuji/6111527 to your computer and use it in GitHub Desktop.

Select an option

Save xtetsuji/6111527 to your computer and use it in GitHub Desktop.
"Bitwise And" of String and String on perl.
use strict;
use warnings;
use Test::More;
# Those are stringify after.
my ($x, $y) = (15, 8);
# Only STRING and STRING bitwise-and is compared by ASCII!!!
ok( !("$x" & "$y"), qq/is "$x" & "$y" = @{[ "$x" & "$y" ]} not true?/);
ok($x & "$y", qq/is $x & "$y" = @{[ $x & "$y" ]} true?/);
ok("$x" & $y, qq/is "$x" & $y = @{[ "$x" & $y ]} true?/);
ok($x & $y, qq/is $x & $y = @{[ $x & $y ]} true?/);
# Cast to number!
ok("$x"+0 & "$y"+0, qq/is "$x" & "$y" = @{[ "$x"+0 & "$y"+0 ]} true?/);
done_testing();
# see: http://www10.plala.or.jp/hakoten/com/perl/no8.html
__END__
ogata@languedechat:~$ prove -v bitwise-15and8.t
bitwise-15and8.t ..
ok 1 - is "15" & "8" = 0 not true?
ok 2 - is 15 & "8" = 8 true?
ok 3 - is "15" & 8 = 8 true?
ok 4 - is 15 & 8 = 8 true?
ok 5 - is "15" & "8" = 8 true?
1..5
ok
All tests successful.
Files=1, Tests=5, 0 wallclock secs ( 0.01 usr 0.00 sys + 0.01 cusr 0.00 csys = 0.02 CPU)
Result: PASS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment