Last active
August 29, 2015 14:07
-
-
Save AlbertoMonteiro/9f97f6b09fa8a74b0e5e to your computer and use it in GitHub Desktop.
Modulo11 para a validação de PIS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static string Mod11(string pis) | |
{ | |
var sum = 0; | |
var fat = 2; | |
for (var i = pis.Length-1; i >= 0; i--) | |
{ | |
sum += Convert.ToInt32(pis[i].ToString()) * fat; | |
fat++; | |
if (fat > 9) | |
fat = 2; | |
} | |
var mdl = sum % 11; | |
if (mdl > 1) | |
return (11 - mdl).ToString()[0].ToString(); | |
return "0"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static string Mod11(string pis) | |
{ | |
var fats = new[] { 2, 3, 4, 5, 6, 7, 8, 9, 2, 3, 4 }; | |
var mod = pis.Reverse().Zip(fats, (x, a) => (char.GetNumericValue(x) * a)).Sum() % 11; | |
return mod > 1 ? (11 - mod).ToString().Substring(0, 1) : "0"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment