I am wondering how to convert an integer to a long_integer and a long_integer to a Positive_Count. Every way I have tried has given me and error even though the conversion should be easy in that instance.
For example, doing
long := long_integer(int1) + long_integer(int2);
will make long a negative value sometimes even though both integer were positive.
The code of the function I'm running , steps split for debugging:
--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;
calling the function:
calcKey("0123456789abcdef",k);
calcKey("0123456789abcdef",k);
calcKey("0123456789abcdef",k);
calcKey("0123456789abcdef",k);
calcKey("fedvba9876543210",k);
calcKey("fedvba9876543210",k);
The output:
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