@b = qw[ 1 0 0 0 ];; $n = 0; $n <<= 1, $n |= $_ for @b; $n = ~$n & 0xf; ## Additional step to bitwise-not and mask (flip) values. print $n;; 7