in reply to Re: Flipping partial bits
in thread Flipping partial bits

The high bit does not need to be masked. Something like:
for my $x (0..0xff) { my $y = ( $x & 0x80 ) ? -($x ^ 0xff) : $x; say "$x $y" }

Replies are listed 'Best First'.
Re^3: Flipping partial bits
by haukex (Archbishop) on Nov 14, 2020 at 12:08 UTC
    The high bit does not need to be masked.

    Yes, that's true, though I felt the specs were a little bit lacking (hence my request for more examples), which is why I played it safe and showed how to do the masking too.