comp.lang.ada
 help / color / mirror / Atom feed
From: chris <spamoff.danx@ntlworld.com>
Subject: Re: Any examples of Byte Ordering Functions
Date: Sun, 19 Oct 2003 18:52:58 +0100
Date: 2003-10-19T18:52:58+01:00	[thread overview]
Message-ID: <d6Akb.6022$mM1.5008@newsfep4-winn.server.ntli.net> (raw)
In-Reply-To: <bmufht$ht2$1@sparta.btinternet.com>

Martin Dowie wrote:

> You don't need to look up the RM (Annex B.2) wrt the
> predefined modular types in package "Interfaces" and there
> you will find Shift_Left/Shift_Right/etc routines. These are
> defined as "Intrinsic", which means they are "built in" to the
> compiler - i.e. it should have a blinking good idea of a good
> representation of this on the target h/w.

Didn't know about that, thanks!  That means if we want to output any 
word to a stream in big endian we can do:

    procedure Write_Big_Endian
          (Stream : access Root_Stream_Type'Class;
           W      : in Word) is
       A, B : Byte;
    begin
       A := Byte (Shift_Right (Unsigned_32(W), 8));
       B := Byte (W and 16#00FF#);

       Byte'Write (Stream, A);
       Byte'Write (Stream, B);
    end Write_Big_Endian;


and for little endian we can do:

    procedure Write_Little_Endian
          (Stream : access Root_Stream_Type'Class;
           W      : in Word) is
       A, B : Byte;
    begin
       A := Byte (W and 16#00FF#);
       B := Byte (Shift_Right (Unsigned_32(W), 8));
       Byte'Write (Stream, B);
       Byte'Write (Stream, A);
    end Write_Little_Endian;

and this will work whatever the platform we compile on?




  reply	other threads:[~2003-10-19 17:52 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-10-15 17:42 Any examples of Byte Ordering Functions Bill Sheehan
2003-10-15 18:55 ` Larry Kilgallen
2003-10-15 18:44   ` Hyman Rosen
2003-10-16  1:01     ` James Rogers
2003-10-16 13:32       ` Hyman Rosen
2003-10-16 14:59       ` Martin Dowie
2003-10-16 20:00         ` tmoran
2003-10-17 12:08           ` Martin Dowie
2003-10-19 15:22         ` chris
2003-10-19 17:25           ` (see below)
2003-10-19 13:45     ` chris
2003-10-19 16:53       ` Martin Dowie
2003-10-19 17:52         ` chris [this message]
2003-10-19 19:24           ` Martin Dowie
2003-10-19 20:47           ` Jeffrey Carter
2003-10-19 22:53             ` tmoran
2003-10-20  4:14               ` Jeffrey Carter
2003-10-23 20:36       ` Laurent Pautet
2003-10-23 21:37         ` Simon Wright
2003-10-24  4:37           ` Simon Wright
2003-10-26 15:05           ` Georg Bauhaus
2003-10-23 20:44       ` Laurent Pautet
2003-10-23 21:03       ` Laurent Pautet
2003-10-15 19:58 ` Frank J. Lhota
2003-10-16 16:28 ` Stephen Leake
replies disabled

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