in reply to fast bit twiddling
See 'perldoc -f vec' for a faster, better way of handling bitfields. All the rest is bitwise operator magic.
That code is structured as a closure to keep $str private, but that can be loosened.{ vec(my $str, 2, 1) = 1; vec($str, 5, 1) = 1; vec($str, 8, 1) = 1; sub mytest { my $foo = @_ ? shift : $_; # was 'shift || $_' $foo <<= 1; $str & $foo == $str; } }
Update: Oops, wrong tests. that checks for equality. Here's the real thing,
( hope that's right! ;-) The Ancient Philosophy And Programming Languages thread should have said something about Aristotle's formal logic.{ vec(my $str, 2, 1) = 1; vec($str, 5, 1) = 1; vec($str, 8, 1) = 1; sub mytest { my $foo = @_ ? shift : $_; # was 'shift || $_' my $bar = $foo << 1; not ($foo & $str) ^ ($bar & $str); } }
Update2: modified mytest's argument handling to behave properly with a numerically false argument.
After Compline,
Zaxo
|
|---|