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.3 required=5.0 tests=BAYES_00,INVALID_MSGID, MSGID_RANDY autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,8309f2bc055237c4 X-Google-Attributes: gid103376,public From: Robert Dewar Subject: Re: Bit manipulation Date: 2000/11/13 Message-ID: <8uoq5g$of6$1@nnrp1.deja.com>#1/1 X-Deja-AN: 693052426 References: <8u8v6n$b7o$1@nnrp1.deja.com> <2WTH$pdrCfOd@eisner.decus.org> <8ub6kt$6nd$1@nnrp1.deja.com> <8ubeq8$cgm$1@nnrp1.deja.com> <3A0D38E9.BB87D8CD@mindspring.com> X-Http-Proxy: 1.0 x64.deja.com:80 (Squid/1.1.22) for client 205.232.38.240 Organization: Deja.com - Before you buy. X-Article-Creation-Date: Mon Nov 13 13:26:14 2000 GMT X-MyDeja-Info: XMYDJUIDrobert_dewar Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/4.61 [en] (OS/2; I) Date: 2000-11-13T00:00:00+00:00 List-Id: In article , lutz@iks-jena.de (Lutz Donnerhacke) wrote: > * Redryder wrote: > >I need to swap the bits in a 32-bit word. > > type word32 is 0 .. 2**32-1; > > procedure swap32 (i : in word32) returns word32 is > type lowrec is record data : word32; end record; > type highrec is record data : word32; end record; > for lowrec'Bit_Order use Low_Order_First; > for highrec'Bit_Order use High_Order_First; > > function l2h is new Ada.Unchecked_Conversion (lowrec, highrec); > > low : lowrec := (i); > high : highrec := l2h(low); > begin > return high; > end swap32; > > It's up to your compiler to find out what's a effictive way to > implement this. No, this is completely wrong. Once again, it is *really* a good idea to actually try out something before posting it here. Bit_Order confuses many people, since certainly it *sounds* as though it might do what you expected, but most certainly it does *not* do anything of the kind. In fact the solution above is doubly wrong, because the use of unchecked conversion ensures that nothing actually happens at all! You clearly did not compile the code, or you would have seen other errors as follows: 1. procedure when you meant function 2. returns when you meant return 3. positional aggregate with only one component 4. wrong return type All in all, these few lines of code contain a rather high density of errors, and certainly do not inform this discussion. It does not take much effort to try out any code you post. I always do, because even for a simple program, I do not trust myself to avoid silly mistakes :-) In any case, read the GNAT documentation to understand what the real situation here is. The operable sentence from the GNAT Reference Manual is In the case where the non-standard value is specified, the effect is to renumber bits within each bit, but the ordering of bytes is not affected. let alone ordering of bits!!!! Sent via Deja.com http://www.deja.com/ Before you buy.