前面我说了,由于整数变量范围的原因,转换后的结果和你手算是不一样的,因为手算结果会超出变量的范围。
不过因为注册码是代码计算的,所以转换你也可以用同一代码来进行。你把代码做下面的调整就可以得到你所要的结果了。
// 生成注册码
SerialNum := -2097461511; // 你提取出来的数字
MsgBox('你提取的数字: ' + IntToStr(SerialNum), mbInformation, MB_OK); // 显示你给的数字
SerialNum := 567890123 - SerialNum; // 转换为实际的序号
MsgBox('转换后的实际序号: ' + IntToStr(SerialNum), mbInformation, MB_OK); // 显示实际序号
if SerialNum > 432109876 then
SN:= SerialNum-432109876
else
SN:= 432109876-SerialNum;
MID:='';
tmp1:= IntToStr(SN);
while length(tmp1)>3 do
begin
tmp2:= copy(tmp1,1,3);
delete(tmp1,1,3);
MID:= MID+Chr(65+StrToInt(tmp2)*26/999)+tmp2;
end;
MID:= MID+Chr(65+StrToInt(tmp1)*26/999)+tmp1;
tmp1:= MID;
MID:= '';
while length(tmp1)>3 do
begin
tmp2:= copy(tmp1,1,3);
delete(tmp1,1,3);
MID:= MID+tmp2+'-';
end;
MID:= MID+tmp1;
If SerialNum > 432109876 then
MID:='3P6-'+MID
else
MID:='X5B-'+MID;
MsgBox('注册码是: ' + MID, mbInformation, MB_OK); // 显示注册码
result:= MID;
end;