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-Thread: 103376,9dec3ff1604723d9 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!news.maxwell.syr.edu!transit.news.xs4all.nl!195.241.76.212.MISMATCH!tiscali!transit1.news.tiscali.nl!dreader2.news.tiscali.nl!not-for-mail Newsgroups: comp.lang.ada Subject: Re: Bitmanipulation in Ada References: <87k6vwrwym.fsf@insalien.org> From: Ludovic Brenta Date: Wed, 18 Aug 2004 23:16:06 +0200 Message-ID: <87ekm4rvu1.fsf@insalien.org> User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) Cancel-Lock: sha1:1YGFyggarCGF6RFNF0xvzi6tccI= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Organization: Tiscali bv NNTP-Posting-Date: 18 Aug 2004 23:16:43 CEST NNTP-Posting-Host: 83.134.237.203 X-Trace: 1092863803 dreader2.news.tiscali.nl 62388 83.134.237.203:35663 X-Complaints-To: abuse@tiscali.nl Xref: g2news1.google.com comp.lang.ada:2817 Date: 2004-08-18T23:16:43+02:00 List-Id: (Bernd Specht) writes: > Ok. Is there a reason why it is not (directly) available in the language > itself like the and/or/xor or the >> and << in C? Yes. As I said, in Ada, modular types do not necessarily have a power of two as their modulo; nor do they necessarily have a "natural" size. You could have for example: type T is mod 17; for T'Size use 43; Since C only has modular types, and since all types in C have "natural" sizes, it makes sense to provide the shift and rotate operations in the language. >> If what you really want is to convert an integer to a byte array, use >> Unchecked_Conversion: > > OK, but this would result in an assignment operation (a memory move on > maschine code level). What I want is a real "overlay" (same storage location > used for both), so reading the value would not need extra instructions. Ah, OK. procedure P is type Byte_Array is array (1 .. Integer'Size) of Boolean; pragma Pack (Byte_Array); for Byte_Array'Size use Integer'Size; I : Integer := 42; B : Byte_Array; -- Specify that B and I are at the same address for B'Address use I'Address; begin for J in B'Range loop Ada.Text_IO.Put_Line (Boolean'Image (B (J))); end loop; end P; HTH -- Ludovic Brenta.