comp.lang.ada
 help / color / mirror / Atom feed
From: lutz@iks-jena.de (Lutz Donnerhacke)
Subject: Re: Bit manipulation
Date: 2000/11/13
Date: 2000-11-13T00:00:00+00:00	[thread overview]
Message-ID: <slrn9104p4.l5.lutz@taranis.iks-jena.de> (raw)
In-Reply-To: 8up1j4$uqe$1@nnrp1.deja.com

* Robert Dewar wrote:
>  lutz@iks-jena.de (Lutz Donnerhacke) wrote:
>> GNAT can not compile it. Bit_Order can not be set.
>
>That is incorrect, as of version 3.13, GNAT implements the capability of
>setting Bit_Order in situations where this makes sense, including this
>one.

Great. I found the announcement (it was posted while I was unable to access
any computer)

>Not at all! Setting Bit_Order is quite valuable for some situations of
>endian independence. You are just confused about the purpose and semantics
>of this capability. The fact that it does not do what you want it to do
>does not make it senseless!

>A typical useful application is to specify the position of bits within a
>single byte as 8 record componens in a manner that is endian-independent.

This would ease one of my programming issues. Fine.

>Not evan vaguely. Like many people you are confusing byte endianness with
>bit order.

I see your point. So word8 can only be used:

with Ada.Unchecked_Conversion;
with System;

procedure endian is
  type word8 is mod 2**8;
  type word32 is mod 2**32;
  type composite is array (1..4) of word8;
  pragma Pack(composite);

  type  lowrec is record   val: composite;   end record;
  type highrec is record   val: composite;   end record;
  for  lowrec'Bit_Order use System.Low_Order_First;
  for highrec'Bit_Order use System.High_Order_First;

  function w32tohigh is new Ada.Unchecked_Conversion(word32, highrec);
  function lowtow32  is new Ada.Unchecked_Conversion(lowrec, word32);

  function h2l32 (h : word32) return word32 is
     hr : highrec := w32tohigh (h);
     lr : lowrec;
  begin
     lr.val(1) := hr.val(4);
     lr.val(2) := hr.val(3);
     lr.val(3) := hr.val(2);
     lr.val(4) := hr.val(1);
     return lowtow32 (lr);
  end h2l32;
begin
  null;
end endian;


>I would recommend reading the section in my book on Microprocessors on
>this subject which is at least an attempt to sort this out.

Google did not came back with an URL. May I ask for a hint?

>We do indeed! The Bit_Order attribute in Ada talks ONLY about numbering of
>the bits, it does NOT provide a facility for reversing bits AT ALL!

Yep. I read the passage, but was unable to understand it correctly.

>So that is why you should read the documentation carefully. Norman Cohen
>has also written a useful piece on Bit_Order, it is in one of the relevant
>AI's. Perhaps someone can give the reference.

URL? Google is very quite on this keywords, too.

>One even has to wonder if the original questioner *really* wants to do
>what he says he wants to do. In my experience, most people who want to
>reverse bits, don't really want to, they are confused in the same way that
>Lutz was confused into thinking that endianness switching involves
>bit-reversal.

>of course there are legitimate requirements for bit order swaps in the
>communications area, but you have to wonder ....

Can I use GNAT 3.13 to work with Token Ring MACs ;-)




  reply	other threads:[~2000-11-13  0:00 UTC|newest]

Thread overview: 71+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-11-07  0:00 Bit manipulation Sandro Binetti
2000-11-07  0:00 ` gdemont
2000-11-08  7:22   ` Sandro Binetti
2000-11-07  0:00 ` Larry Kilgallen
2000-11-07  0:00   ` John English
2000-11-08  0:00   ` gdemont
2000-11-08  0:00     ` Robert Dewar
2000-11-08  0:00       ` Sandro Binetti
2000-11-08  0:00         ` gdemont
2000-11-09  4:00           ` Ken Garlington
2000-11-09  0:00             ` Larry Kilgallen
2000-11-09  0:00               ` Ken Garlington
2000-11-08  0:00         ` Nicolas Brunot
2000-11-08  0:00         ` Dale Stanbrough
2000-11-09  0:00           ` Sandro Binetti
2000-11-09  0:00             ` gdemont
2000-11-09  0:00             ` Ken Garlington
2000-11-10  0:00             ` Scott Ingram
2000-11-09  3:59         ` Ken Garlington
2000-11-09  4:52         ` Robert Dewar
2000-11-08  0:00       ` gdemont
2000-11-08  0:00         ` Larry Kilgallen
2000-11-09  4:50           ` Robert Dewar
2000-11-10  0:00             ` Lao Xiao Hai
2000-11-09  4:47         ` Robert Dewar
2000-11-09  0:00           ` gdemont
2000-11-11  0:00       ` Redryder
2000-11-11  0:00         ` Jeff Carter
2000-11-11  0:00           ` Redryder
2000-11-12  2:07             ` Ken Garlington
2000-11-12  5:56             ` Jeff Carter
2000-11-12  0:00               ` Robert Dewar
2000-11-12  0:00                 ` tmoran
2000-11-13  0:00                   ` Robert Dewar
2000-11-14  0:00                     ` Marc A. Criley
2000-11-13  0:54                   ` Ken Garlington
2000-11-12  6:40               ` tmoran
2000-11-13  0:00         ` Lutz Donnerhacke
2000-11-13  0:00           ` Robert Dewar
2000-11-13  0:00             ` Lutz Donnerhacke
2000-11-13  0:00               ` Robert Dewar
2000-11-13  0:00                 ` Lutz Donnerhacke
2000-11-13  0:00           ` Robert Dewar
2000-11-13  0:00             ` Lutz Donnerhacke
2000-11-13  0:00               ` Robert Dewar
2000-11-13  0:00                 ` Lutz Donnerhacke [this message]
2000-11-13  0:00                   ` Pat Rogers
2000-11-13  0:00                     ` Brian Rogoff
2000-11-13  0:00                       ` F. Britt Snodgrass
2000-11-15  0:00                         ` Lutz Donnerhacke
2000-11-13  0:00                       ` Pat Rogers
2000-11-14  0:00                       ` Georg Bauhaus
2000-11-15  0:00                         ` Lutz Donnerhacke
2000-11-14  0:00                   ` Martin Dowie
2000-11-15  0:00                     ` Lutz Donnerhacke
2000-11-20  0:00                 ` Randy Brukardt
2000-11-21  0:00                   ` Lutz Donnerhacke
2000-11-21  0:00                     ` Stephen Leake
2000-11-22  0:00                       ` Lutz Donnerhacke
2000-11-08  7:18   ` Sandro Binetti
2000-11-10  7:24 ` Thank you all for your contribution ! Sandro Binetti
  -- strict thread matches above, loose matches on Subject: below --
2005-02-07 12:37 Bit manipulation Maurizio
2005-02-07 13:20 ` Martin Krischik
2005-02-07 15:32 ` Martin Dowie
2005-02-07 18:04   ` Martin Krischik
2005-02-08  0:32 ` Randy Brukardt
2005-02-08  3:11 ` Steve
2005-02-08 18:51   ` tmoran
1999-04-04  0:00 bit manipulation Jack Chow
1999-04-04  0:00 ` Matthew Heaney
1999-04-05  0:00 ` dennison
replies disabled

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