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!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!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: <87k6vwrwym.fsf@insalien.org> Organization: No company Message-ID: User-Agent: Xnews/4.05.03 Date: 18 Aug 2004 21:10:30 GMT NNTP-Posting-Date: 18 Aug 2004 23:10:30 MEST NNTP-Posting-Host: f20e52fc.newsread2.arcor-online.net X-Trace: DXC=djmdS4oCW>XJ<1FClJbQ`\Q5U85hF6f;TjW\KbG]kaMXdglQn]=09hTC44h[jKbe7YmfobaMi:^o^oeekY`ijE\RL;0?FRC4:;R X-Complaints-To: abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:2814 Date: 2004-08-18T23:10:30+02:00 List-Id: Ludovic Brenta wrote in news:87k6vwrwym.fsf@insalien.org: > (Bernd Specht) writes: >> Hi, Thanks. >> 2. I did not found shift and rotate operations. Did I miss something >> or are there really none? > > These operations are usually carried out in hardware for certain sizes > of modular integers only. Consequently, these operations are defined > in package Interfaces (see RM 3.5.4(31) and B.2). Package Interfaces > defines the following subprograms: > > function Shift_Left (Value : Unsigned_n; > Amount : Natural) return Unsigned_n; > function Shift_Right (Value : Unsigned_n; > Amount : Natural) return Unsigned_n; > function Shift_Right_Arithmetic (Value : Unsigned_n; > Amount : Natural) > return Unsigned_n; > function Rotate_Left (Value : Unsigned_n; > Amount : Natural) return Unsigned_n; > function Rotate_Right (Value : Unsigned_n; > Amount : Natural) return Unsigned_n; 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? >> 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 >> Such overlay structures are not valid with Ada, so what do instead? > > Have you considered a variant record? > > type Ov (T : Boolean) is record > case T is > when True => I : Integer; > when False => B : Byte_Array; > end T; > end record; I found, that (at least GNAT) different storage locations are used for i and b. > 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.