AI摘要
文章介绍了一个Delphi实现的身份证号码从15位升到18位的算法。算法通过插入出生年份“19”,计算加权和,然后根据模11的结果确定最后一位校验码。代码包括权重数组W和校验码数组A,以及一个函数GetNewID,用于实现升位算法。
文章介绍了一个De
身份证号码15到18位升位算法Delphi实现
2000年写的一个函数,大家用得上的话可以看看:
function GetNewID(ID: string): string;
const
W: array[1..18] of Integer = (7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1);
A: array[0..10] of Char = ('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
var
i, j, S: integer;
NewID: string;
begin
if Length(ID) <> 15 then
result := ''
else
begin
NewID := ID;
Insert('19', NewID, 7);
S := 0;
try
for i := 1 to 17 do
begin
j := StrToInt(NewID[i]) * W[i];
S := S + j;
end;
except
result := '';
exit;
end;
S := S mod 11;
Result := NewID + A[S];
end;
end;