#!/usr/bin/perl -s use v5.16; use Test2::V0; use experimental 'signatures'; our ($tests, $examples); run_tests() if $tests || $examples; # does not return die <>= 1; # Flip bits and mask the significant bits. ~$n & ($l - 1); } ### Examples and tests sub run_tests { SKIP: { skip "examples" unless $examples; is flip_bits(5), 2, 'Example 1'; is flip_bits(4), 3, 'Example 2'; is flip_bits(6), 1, 'Example 3'; } SKIP: { skip "tests" unless $tests; is flip_bits(0), 1, 'out of scope: 0'; is flip_bits(-1), 0, 'out of scope: -1'; is flip_bits(-2), 1, 'out of scope -2'; is flip_bits(0x8000), 0x7fff, 'flip 16 bits'; is flip_bits(85), 42, 'The universal question'; { no warnings 'portable'; is flip_bits(0x8000000000000000), 0x7fffffffffffffff, 'flip 64 bits'; } } done_testing; exit; }