Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8927103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:08:38+00:00 2026-06-15T08:08:38+00:00

I am wondering how to convert an integer to a long_integer and a long_integer

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T08:08:39+00:00Added an answer on June 15, 2026 at 8:08 am

    (THis should be a comment, but it’s too long so I’m submitting it as an answer)

    First thing I would do is actually verify that long_int is what you think it is, i.e doing INTEGER'SIZE and LONG_INTEGER'SIZE, it could very well be that on your platform they are the very same size,

    From the Ada definition:

    Note that the ranges and sizes of these types can be different in
    every platform (except of course for Boolean and
    [[Wide_]Wide_]Character). There is an implementation requirement that
    the size of type Integer is at least 16 bits, and that of Long_Integer
    at least 32 bits (if present) RM 3.5.4 (21..22) (Annotated). So if you
    want full portability of your types, do not use types from Standard
    (except where you must, see below), rather define you own types. A
    compiler will reject any type declaration whose range it cannot
    satisfy.

    If they are the same size you could be overflowing when you add 2 really large ints, thus giving the results you see.

    Source: http://en.wikibooks.org/wiki/Ada_Programming/Libraries/Standard

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering what the easiest way is to convert an integer to the
I was wondering if there was a way to directly convert the integer DayOfWeek
I was wondering how can convert CGcolorRef to UIColor ? I have created a
I was wondering if there was a way to convert a self subquery to
Is there a built in easy way to convert a string into an integer,
I was wondering if there was an easy way in SQL to convert an
I have a list of integers, List<Integer> and I'd like to convert all the
I was wondering if there was any way to convert a variable of type
I have this (XLinq) query and was wondering how to convert it to the
I was wondering what the easiest way to convert a UUID to a unique

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.