in reply to Bitwise operations
If I have four corners with the values 1,0,0,0 how would I go about building the index - for these values the result should be 7.
Erm. Binary 1000 is 8 not 7. Unless you invert the bits, but I don't see any call for that in a quick scan of the page you linked.
If you have an 4 element array containing the 1s & 0s, you could build the numeric value this way:
@b = qw[ 1 0 0 0 ];; $n = 0; $n <<= 1, $n |= $_ for @b; print $n;; 8 @b = qw[ 0 1 1 1 ];; $n = 0; $n <<= 1, $n |= $_ for @b; print $n;; 7
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Bitwise operations
by bangor (Monk) on Jan 08, 2014 at 22:23 UTC | |
by BrowserUk (Patriarch) on Jan 09, 2014 at 05:21 UTC |