Remove code duplication for bitlength checks.