DRY code for bitwise operations