Why is there a special rule only for state codes 01 and 02?
Historically, a check digit of 0 for those two specific codes caused ambiguity in manual voter-registry processing; the rule forces the value to 1 in that specific case, so a validator that skips this exception will flag a legitimate state 01/02 voter ID as invalid.
Can I compute both check digits in a single function, without splitting into two steps?
You can write it as a single function, but the internal computation stays sequential: the second check digit uses the first one numeric value as one of its three summed terms, so trying to parallelize them, or computing both from just the sequential block and state code without that dependency, produces an invalid number.
Does state code 28 (abroad) follow the same formula as the other 27?
Yes, the calculation for both check digits is identical across all 28 codes, including 28 reserved for voters abroad; the only rule that changes per code is the remainder-0-becomes-1 exception, and it applies only to codes 01 and 02, not to 28.
How do I check whether my state code falls within the valid range?
Confirm the two digits form a number between 01 and 28 inclusive; anything outside that range (00, or 29 and above) does not correspond to any real state or abroad-voter code, so validation should reject it before even attempting the second check digit calculation.