一、关于车辆的VIN码介绍: 直接百度
二、VIN码的校验位是第九位,对于第九位的计算方法如下:
2.1 内容的权值:VIN码各位数字的“对应值”:
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
A |
B |
C |
D |
E |
F |
G |
H |
J |
K |
L |
M |
N |
P |
R |
S |
T |
U |
V |
W |
X |
Y |
Z |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
1 |
2 |
3 |
4 |
5 |
7 |
9 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
2.2 位置的权值: VIN码从第1位到第17位的“加权值”:
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
8 |
7 |
6 |
5 |
4 |
3 |
2 |
10 |
0 |
9 |
8 |
7 |
6 |
5 |
4 |
3 |
2 |
VIN码从从第一位开始,码数字的对应值×该位的加权值,计算全部17位的乘积值相加除以11,所得的余数,即为第九位校验值
例子:车辆识别码:UU6JA69691D713820第九位为9为校验码,我们可以验证下是否正确。
4×8+4×7+6×6+1×5+1×4+6×3+9×2+6×10+1×9+4×8+7×7+1×6+3×5+8×4+2×3+0×0 = 350
350除以11,得31,余9,该余数9即为校验码,和识别码的校验位相同。如果余数为10,则检验位为字母“X”
-----------------------------------我是分割线---------------------------------------
#include "stdio.h"
#define GD_OK 1
#define GD_ERR -1
int VinCalc(char *Vin,char *reslt)
{
unsigned int i = 0;
unsigned int sum =0;
unsigned int check = 0;
char temp=0;
unsigned int j = 0;
char jianquan[26][2] = {
{'A',1},{'B',2},{'C',3},{'D',4},{'E',5},{'F',6},
{'G',7},{'H',8},{'I',0},{'J',1},{'K',2},{'L',3},
{'M',4},{'N',5},{'O',0},{'P',7},{'Q',8},{'R',9},
{'S',2},{'T',3},{'U',4},{'V',5},{'W',6},{'X',7},
{'Y',8},{'Z',9}};
char pos[17]={8,7,6,5,4,3,2,10,0,9,8,7,6,5,4,3,2};
for(i=0;i<17;i++)
{
if(Vin[i]>='a'&&Vin[i]<='z')
{
temp = Vin[i]-0x20;
}
else if((Vin[i]>='A')&&(Vin[i]<='Z'))
{
temp = Vin[i];
}
else if((Vin[i]>='0')&&(Vin[i]<='9'))temp = Vin[i]-'0';
else return GD_ERR;
if((temp>='A')&&(temp<='Z'))
{
for(j=0;j<26;j++)
{
if(temp == jianquan[j][0])
temp = jianquan[j][1];
}
}
check += temp*pos[i];
}
*reslt = check%11;
return GD_OK;
}
void main(void)
{
char check = 0;
char* Vin="UU6JA69691D713820";
VinCalc(Vin,&check);
printf("校验位是:%d",check);
}