From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,64599bfe530783cd X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-10-19 10:46:50 PST Path: archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed.freenet.de!news2.euro.net!newspeer1-gui.server.ntli.net!ntli.net!newsfep4-winn.server.ntli.net.POSTED!53ab2750!not-for-mail From: chris User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5) Gecko/20031014 Thunderbird/0.3 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Any examples of Byte Ordering Functions References: <1066243458.911546@master.nyc.kbcfp.com> In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Date: Sun, 19 Oct 2003 18:52:58 +0100 NNTP-Posting-Host: 81.98.236.129 X-Complaints-To: abuse@ntlworld.com X-Trace: newsfep4-winn.server.ntli.net 1066585609 81.98.236.129 (Sun, 19 Oct 2003 18:46:49 BST) NNTP-Posting-Date: Sun, 19 Oct 2003 18:46:49 BST Organization: ntl Cablemodem News Service Xref: archiver1.google.com comp.lang.ada:1148 Date: 2003-10-19T18:52:58+01:00 List-Id: 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?