From: chris <spamoff.danx@ntlworld.com>
Subject: Re: Any examples of Byte Ordering Functions
Date: Sun, 19 Oct 2003 14:45:38 +0100
Date: 2003-10-19T14:45:38+01:00 [thread overview]
Message-ID: <muwkb.3583$KA5.30712@newsfep4-glfd.server.ntli.net> (raw)
In-Reply-To: <1066243458.911546@master.nyc.kbcfp.com>
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
next prev parent reply other threads:[~2003-10-19 13:45 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 [this message]
2003-10-19 16:53 ` Martin Dowie
2003-10-19 17:52 ` chris
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