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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,9dec3ff1604723d9 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!proxad.net!newsfeed.stueberl.de!uucp.gnuu.de!newsfeed.arcor.de!news.arcor.de!not-for-mail Newsgroups: comp.lang.ada Subject: Re: Bitmanipulation in Ada From: Bernd.Specht@gmx.com (Bernd Specht) References: Organization: No company Message-ID: User-Agent: Xnews/4.05.03 Date: 19 Aug 2004 17:46:56 GMT NNTP-Posting-Date: 19 Aug 2004 19:46:56 MEST NNTP-Posting-Host: 18f56e32.newsread2.arcor-online.net X-Trace: DXC=]g`h]:EN3N9::C@ZGckeZ1Q5U85hF6f;4jW\KbG]kaM8dglQn]=09h4CYnlA3gMKn7mfobaMi:^o>QfEN5o;5\`4]I270aX5_Q8 X-Complaints-To: abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:2864 Date: 2004-08-19T19:46:56+02:00 List-Id: Many thanks, this will help me a lot. "Martin Dowie" wrote in news:cg0j57$bal$1@sparta.btinternet.com: > Bernd Specht wrote: >> 2. I did not found shift and rotate operations. Did I miss something >> or are there really none? > > Check out package "Interfaces" they are all there - as are some common > predefined types. > >> 3. When I want treat a value both as an integer and as a boolean >> array, how can i do this? In pascal I would use a tagless record like > > Assuming you had a _really_ good reason to need to think of the data in > both terms, you have a number of options: > > 1) Unchecked_Conversion; > > procedure Foo (Y : Unsigned_8) is > procedure To_Array_8 is > new Ada.Unchecked_Conversion (Unsigned_8, Array_8); > X : Array_8 := To_Array_8 (Y); > begin > ... > > 2) Address clause to 'overlay' 2 variables at the same address; > > procedure Foo (Y : Unsigned_8) is > X : Array_8; > for X'Address use Y'Address; > begin > ... > > 3) Variant record with a representation clause; > > type Variant (Is_Array : Boolean := False) is > record > case Is_Array is > when False => > U : Unsigned_8; > when True => > A : Array_8; > end case; > end record; > for Variant use > record > U at 0 range 0 .. 7; > A at 0 range 0 .. 7; > end record; > > This will leave it to the compiler where to put "Is_Array" > > There are pros and cons to each - I'd rather use > Ada.Unchecked_Conversion to make it explicit that I'm switching > representations. > > Cheers > > -- Martin > >