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,4ac6504560f5ef27 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2004-02-25 22:02:57 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!news-FFM2.ecrc.net!kibo.news.demon.net!news.demon.co.uk!demon!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Little Endian -> Big Endian (Ada95 / GNAT) Date: 26 Feb 2004 05:59:15 +0000 Organization: Pushface Sender: simon@smaug.pushface.org Message-ID: References: NNTP-Posting-Host: pogner.demon.co.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: news.demon.co.uk 1077775375 10061 62.49.19.209 (26 Feb 2004 06:02:55 GMT) X-Complaints-To: abuse@demon.net NNTP-Posting-Date: Thu, 26 Feb 2004 06:02:55 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.1 Xref: archiver1.google.com comp.lang.ada:5823 Date: 2004-02-26T05:59:15+00:00 List-Id: jamesamor@hotmail.com (James Amor) writes: > At present I am writing a tool to create a file which contains various > extracted ELF symbols. The output data structure, a list of unsigned > 32's, is to be used as part of an image on a PowerPC target. If you output source code in your language of choice (C for this part of the job, even!) you could compile it with the target compiler. > Problem: As it is compiled on Wintel the tool is producing an output > in little endian and PowerPC is big endian! > > Question: How do I modify my code to write the output in big endian > format? Roughly, with Ada.Streams; with Ada.Unchecked_Conversion; with Interfaces; with System; function To_Big_Endian (N : Interfaces.Unsigned_32) return Interfaces.Unsigned_32 is begin if System."=" (System.Default_Bit_Order, System.Low_Order_First) then declare subtype Bytes is Ada.Streams.Stream_Element_Array (1 .. 4); function To_Bytes is new Ada.Unchecked_Conversion (Interfaces.Unsigned_32, Bytes); function From_Bytes is new Ada.Unchecked_Conversion (Bytes, Interfaces.Unsigned_32); B : constant Bytes := To_Bytes (N); begin return From_Bytes ((1 => B (4), 2 => B (3), 3 => B (2), 4 => B (1))); end; else return N; end if; end To_Big_Endian; (compiled but not tested) -- Simon Wright 100% Ada, no bugs.