$bits |= (1<<$val) #### if( unpack( "%16B*", pack("n", $bits)) == 1 ) { my $ret = 0; while (!($bits & 0x1)) { $ret++; $bits >>= 1; }; return $ret; };