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 06:39:30 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.vmunix.org!newspeer1-gui.server.ntli.net!ntli.net!newsfep4-glfd.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: <1066243458.911546@master.nyc.kbcfp.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Date: Sun, 19 Oct 2003 14:45:38 +0100 NNTP-Posting-Host: 81.98.236.129 X-Complaints-To: abuse@ntlworld.com X-Trace: newsfep4-glfd.server.ntli.net 1066570770 81.98.236.129 (Sun, 19 Oct 2003 14:39:30 BST) NNTP-Posting-Date: Sun, 19 Oct 2003 14:39:30 BST Organization: ntl Cablemodem News Service Xref: archiver1.google.com comp.lang.ada:1128 Date: 2003-10-19T14:45:38+01:00 List-Id: Hi, I'm trying to implement reading 16 bit words from a stream with a given endianess (that is the endianess of the items in the stream is known), and think the following implementation is independant of the actual order of bytes in a word variable. Am I right? It'd be nice not to have two versions of this code and have to take different cpu architectures into account at compile time! Can I expect the compiler (gnat say) to optimise multiplication of modular types by *powers of two* to shift lefts (and divisions by powers of two to shift rights)? type Byte is mod 2**8; for Byte'Size use 8; type Word is mod 2**16; for Word'Size use 16; bytes in stream: a b c d e f g h Read Big Endian encoded Word: W := a * 256 + b; Read Little Endian encoded Word: W := b * 256 + a; Cheers, Chris