Looking at the Wikipedia page it should be straightforward. That's what I thought until I saw your example. Why should the result be 7? Should it not be 8? I would think you should do
my @corners = ( 1, 0, 0, 0 ); my $index = 0; ( $index <<= 1 ) |= $_ for @corners; print "$index\n";
which is nothing but translating binary 1000 into decimal (and which can be achieved in a zillion ways in Perl...
In reply to Re: Bitwise operations
by hdb
in thread Bitwise operations
by bangor
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |