我是pascal的新手,目前正在尝试将十六进制数字与用户输入的数字进行比较。
他们输入的数字实际上将与第五,第六和第七数字相同。我试图在下面演示一下:
[目前,我设法让用户输入14位数字,然后将其转换为十六进制,然后识别出串行部分。接下来,我让用户输入一个以0开头的4位数字(0540),我需要将该数字与序列号进行比较。
program licenseTransfer;
Uses sysutils, crt;
var license1, serialNumber, newNum : int64;
serialNumber2 : String;
begin
writeln('Enter Current License:');
readln(license1);;
{debug use}
writeln('License in HEX: ', IntToHex(license1,0));
readln;
{debug use}
write('Serial portion: ');
serialNumber := license1 and $FFF00000;
writeln(IntToHex(serialNumber,12));
readln;
writeln('Enter serial number (S0xxx):');
readln(serialNumber2);
{replace the first letter of the serial with a number'}
serialNumber2[1] := '0';
{convert serialNumber2 string to newNum in Integer value}
newNum := StrToInt(serialNumber2);
writeln(newNum);
writeln('Serial code entered: ', 'S0', newNum);
readln();
end.
输出:
license in hex: 520054001935
Serial Portion: 000054000000
program SO58271986;
uses
sysutils;
var license1, serialNumber : int64;
serialNumber2 : String;
Check : Word;
newNum : Word;
begin
writeln('Enter Current License:');
readln(license1);
{debug use}
writeln('License in HEX: ', IntToHex(license1,0));
{debug use}
write('Serial portion: ');
serialNumber := license1 and $FFF00000;
writeln(IntToHex(serialNumber,12));
writeln('Enter serial number (S0xxx):');
readln(serialNumber2);
{replace the first letter of the serial with a number'}
serialNumber2[1] := '0';
{convert serialNumber2 string to newNum in Integer value}
newNum := StrToInt('$'+serialNumber2);
writeln('Serial code entered: ', 'S', IntToHex(newNum));
Check := serialNumber div $100000; // shift serial portion 5 digits to the right
writeln('Serial check: ', 'S', IntToHex(Check));
if Check <> newNum then
writeln('Invalid serial code!')
else
writeln('Serial code is correct!');
readln;
end.
您几乎正在使用当前代码。2分:
$
符号将其转换为int,以便StrToInt
知道您正在转换的是十六进制值而不是十进制值