2
Hello, I am searching on the internet and found on that website a code in C# of how to calculate RENAVAM, I moved a little, but I can’t find anywhere that explains how RENAVAM calculus actually works so I don’t know if this logic is correct.
Code:
public static bool isRENAVAM(string RENAVAM)
{
if (string.IsNullOrEmpty(RENAVAM.Trim()))
return false;
int[] d = new int[11];
//sequencia para calcular o RENAVAM
string sequencia = "3298765432";
string SoNumero = Regex.Replace(RENAVAM, "[^0-9]", string.Empty);
if (string.IsNullOrEmpty(SoNumero))
return false;
//verificando se todos os numeros são iguais
if (new string(SoNumero[0], SoNumero.Length) == SoNumero)
return false;
SoNumero = Convert.ToInt64(SoNumero).ToString("00000000000");
int v = 0;
for (int i = 0; i < 11; i++)
d[i] = Convert.ToInt32(SoNumero.Substring(i, 1));
for (int i = 0; i < 10; i++)
v += d[i] * Convert.ToInt32(sequencia.Substring(i, 1));
v = (v * 10) % 11;
v = (v != 10) ? v : 0;
return (v == d[10]);
}
My doubts are:
1. This code to calculate RENAVAM is correct?
2. What is the logic for calculating RENAVAM?
3. There’s something I can improve on that code?
1 - Test here with these numbers http://gerador.info/renavam 2 - Good question 3 -
– PauloHDSousa
@Paulohdsousa could post the code with the changes you would make and with the explanation of why would you change them? (Note. yes I am new in this world of programming '-')
– Andrey Hartung
I tested it several times and it worked, and I tested it with broken numbers and gave the right answers, I think I will use this code even, with its improvements
– Andrey Hartung