in reply to Making all nibble zero lower than the offset

There are a few bit manipulation tricks worth knowing about when you are dealing with masking blocks of bits:

#!/usr/bin/env/perl use strict; use warnings; my $oValue = 0xAAAA; my $setBit = 1 << 5; my $mask = $setBit - 1; my $setBits = $oValue | $mask; my $resetBits = $oValue & ~$mask; printf "orig: %016b\n", $oValue; printf " bit: %016b\n", $setBit; printf "mask: %016b\n", $mask; printf " set: %016b\n", $setBits; printf " clr: %016b\n", $resetBits;

Prints:

orig: 1010101010101010 bit: 0000000000100000 mask: 0000000000011111 set: 1010101010111111 clr: 1010101010100000

Note that ~ generates the 1s complement (inverts each bit) of its operand.

Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond