comp.lang.ada
 help / color / mirror / Atom feed
From: Gautier write-only <gautier_niouzes@hotmail.com>
Subject: Re: Does Ada support endiannes?
Date: Wed, 14 Dec 2011 12:16:40 -0800 (PST)
Date: 2011-12-14T12:16:40-08:00	[thread overview]
Message-ID: <6779f55b-e110-4673-b70b-cbd7c58f5d78@j10g2000vbe.googlegroups.com> (raw)
In-Reply-To: 0a7b55fd-1ecf-4a40-979c-12ce44071be9@p9g2000vbb.googlegroups.com

On 14 déc, 17:16, Gerd <Gerd...@t-online.de> wrote:
> Are you sure the "/" and mod would work correct?
>
> Assume, that the Value 16#000000FF# shall be converted to
> 16#FF000000#.
>
> Native : Integer := 16#000000FF#;
>
> Remote : Integer;
>
> Remote := 16#01000000# * ()Native mod 16#000000FF#); -- overflow!
>
> PS: The task is to exchange Integer Values between an Motorola 68k and
> an Intel x86.

Then you will use modular types, and with a definite size.
  Native: Unsigned_32;
  Remote: Unsigned_32;
They never overflow.
But typically (as you can see in Zip-Ada [1]) you won't presume
anything about the native endianness.
The "/" and "mod" (or faster: "Shift_Right" and "and") will do the job
automatically for you.
So your code will work on Intel, PowerPC, 68K - whatever - and
communicate with a remote hardware or media with a specific
endianness.

[1] http://unzip-ada.sf.net/za_html/zip-headers__adb.htm#32_12
_________________________
Gautier's Ada programming
http://gautiersblog.blogspot.com/search/label/Ada
NB: follow the above link for a valid e-mail address



  parent reply	other threads:[~2011-12-14 20:29 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-12  8:57 Does Ada support endiannes? Gerd
2011-12-12  9:23 ` Niklas Holsti
2011-12-12 11:27 ` Dmitry A. Kazakov
2011-12-12 12:44   ` Gerd
2011-12-12 19:23     ` Jeffrey Carter
2011-12-13 14:25       ` Gerd
2011-12-13 14:19     ` Gautier write-only
2011-12-14 16:16       ` Gerd
2011-12-14 18:16         ` Dmitry A. Kazakov
2011-12-14 20:16         ` Gautier write-only [this message]
2011-12-15 11:27           ` Gerd
2011-12-15 13:01             ` Simon Wright
2011-12-15 13:37             ` Dmitry A. Kazakov
2011-12-15 20:12             ` Jeffrey Carter
2011-12-12 12:46   ` Gerd
2011-12-12 13:22     ` Dmitry A. Kazakov
2011-12-12 17:07       ` Charles H. Sampson
2011-12-12 18:33         ` Dmitry A. Kazakov
2011-12-14  5:19           ` Charles H. Sampson
2011-12-14  8:56             ` Dmitry A. Kazakov
2011-12-14  9:46               ` Simon Wright
2011-12-15  9:14               ` Charles H. Sampson
2011-12-15  9:46                 ` Dmitry A. Kazakov
2011-12-25 21:42                   ` Charles H. Sampson
2011-12-26 10:47                     ` Dmitry A. Kazakov
2011-12-27 10:38                       ` Georg Bauhaus
2011-12-27 12:35                         ` Dmitry A. Kazakov
2012-01-04  4:33                       ` Charles H. Sampson
2012-01-04 11:56                         ` Dmitry A. Kazakov
2011-12-12 13:33     ` Robert A Duff
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox