我想知道如何将整数转换为 long_integer,将 long_integer 转换为 Positive_Count。即使在那种情况下转换应该很容易,我尝试过的每一种方法都给了我和错误。
例如,做
long := long_integer(int1) + long_integer(int2);
即使两个整数都是正数,有时也会产生负值。
我正在运行的函数的代码,调试步骤拆分:
--calcKey--
procedure calcKey(x: in String16; key: out External_IO.Positive_Count) is
s1, s2 : String2;
int1, int2 : integer;
long1, long2 : long_integer;
begin
s1 := x(12..13);
s2 := x(15..16);
put_line("s1: " &s1& "- s2: " &s2);
int1 := abs StringToInt(s1);
int2 := abs StringToInt(s2);
put("int1: " & Integer'image(int1) & " | int: " & Integer'Image(int2)); new_line;
long1 := long_integer(int1);
long2 := long_integer(int2);
long1 := long1 + long2;
put_line("long := " & long_integer'Image(long1));
long1 := (long1 mod 256) + 1;
key := External_IO.Positive_Count(long1);
put_line("Key : " & External_IO.Positive_Count'Image(key));
new_line;
end calcKey;
调用函数:
calcKey("0123456789abcdef",k);
calcKey("0123456789abcdef",k);
calcKey("0123456789abcdef",k);
calcKey("0123456789abcdef",k);
calcKey("fedvba9876543210",k);
calcKey("fedvba9876543210",k);
输出:
s1: bc- s2: ef
int1: 2011929758 | int: 1667393125
long := -615644413
Key : 4
s1: bc- s2: ef
int1: 287586 | int: 1667393125
long := 1667680711
Key : 200
s1: bc- s2: ef
int1: 13132642 | int: 1667393125
long := 1680525767
Key : 200
s1: bc- s2: ef
int1: 13132642 | int: 1667393125
long := 1680525767
Key : 200
s1: 43- s2: 10
int1: 13120308 | int: 859058225
long := 872178533
Key : 102
s1: 43- s2: 10
int1: 6697780 | int: 859058225
long := 865756005
Key : 102