package FriedoBits; use strict; use overload '|' => \&bitor; use overload '&' => \&bitand; sub bitor { my ($a, $b) = @_; my $new = [ ]; for(0..3) { $new->[$_] = ( $a->[$_] | $b->[$_] ); } return __PACKAGE__->new( $new ); } sub bitand { my ($a, $b) = @_; my $new = [ ]; for(0..3) { $new->[$_] = ( $a->[$_] & $b->[$_] ); } return __PACKAGE__->new( $new ); } sub new { return bless $_[1], ref($_[0]) || $_[0]; } use constant PERM_0000 => FriedoBits->new( [ 0x00000000, 0x00000000, 0x00000000, 0x00000001 ] ); use constant PERM_0001 => FriedoBits->new( [ 0x00000000, 0x00000000, 0x00000000, 0x00000002 ] ); use constant PERM_0002 => FriedoBits->new( [ 0x00000000, 0x00000000, 0x00000000, 0x00000004 ] ); use constant PERM_0003 => FriedoBits->new( [ 0x00000000, 0x00000000, 0x00000000, 0x00000008 ] ); use constant PERM_0004 => FriedoBits->new( [ 0x00000000, 0x00000000, 0x00000000, 0x00000010 ] ); use constant PERM_0005 => FriedoBits->new( [ 0x00000000, 0x00000000, 0x00000000, 0x00000020 ] ); ... use constant PERM_0125 => FriedoBits->new( [ 0x20000000, 0x00000000, 0x00000000, 0x00000000 ] ); use constant PERM_0126 => FriedoBits->new( [ 0x40000000, 0x00000000, 0x00000000, 0x00000000 ] ); use constant PERM_0127 => FriedoBits->new( [ 0x80000000, 0x00000000, 0x00000000, 0x00000000 ] ); 1;