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,553a6b79b2471571 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!wns14feed!worldnet.att.net!attbi_s71.POSTED!53ab2750!not-for-mail From: "Jeffrey R. Carter" Organization: jrcarter at acm dot org User-Agent: Thunderbird 1.5 (Windows/20051201) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: How do you bitwise operations in Ada '83 and '95 References: <1153244316.853254.291560@m79g2000cwm.googlegroups.com> In-Reply-To: <1153244316.853254.291560@m79g2000cwm.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <6xavg.41699$FQ1.5766@attbi_s71> NNTP-Posting-Host: 12.201.97.176 X-Complaints-To: abuse@mchsi.com X-Trace: attbi_s71 1153250498 12.201.97.176 (Tue, 18 Jul 2006 19:21:38 GMT) NNTP-Posting-Date: Tue, 18 Jul 2006 19:21:38 GMT Date: Tue, 18 Jul 2006 19:21:38 GMT Xref: g2news2.google.com comp.lang.ada:5781 Date: 2006-07-18T19:21:38+00:00 List-Id: In Ada 83, you use packed arrays of Boolean or call a small C or assembler operation. In Ada 95, in addition to this, you can use modular types. function "and" (Left : Integer; Right : Integer) return Integer; -- Returns the bitwise logical and of Left and Right. -- Ada 83: function "and" (Left : Integer; Right : Integer) return Integer is type Bit_Set is array (1 .. Integer'Size) of Boolean; pragma Pack (Bit_Set); function To_Bit is new Unchecked_Conversion (Source => Integer, Target => Bit_Set); function To_Integer is new Unchecked_Conversion (Source => Bit_Set, Target => Integer); LB : constant Bit_Set := To_Bit (Left); RB : constant Bit_Set := To_Bit (Right); begin -- "and" return To_Integer (LB and RB); end "and"; Note the the language does not define whether LB (LB'First) is the LSB or MSB of Left. -- Ada 95: function "and" (Left : Integer; Right : Integer) return Integer is type Mod_Int is mod 2 ** Integer'Size; function To_Mod is new Ada.Unchecked_Conversion (Source => Integer, Target => Mod_Int); funtion To_Integer is new Ada.Unchecked_Conversion (Source => Mod_Int, Target => Integer); LM : constant Mod_Int := To_Mod (Left); RM : constant Mod_Int := To_Mod (Right); begin -- "and" return To_Integer (LM and RM); end "and"; -- Jeff Carter "I'm a lumberjack and I'm OK." Monty Python's Flying Circus 54