Use:
printf "0x%08.8x\n", (~$val & $mask); [download]
to count up.
In reply to Re^2: Incrementing only the masked bits (sure) by GrandFather in thread Incrementing only the masked bits by lyeoh