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 autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,a84a01d2859560a0 X-Google-Attributes: gid103376,public From: "David C. Hoos, Sr." Subject: Re: bit operations on integers Date: 1999/05/03 Message-ID: <7gkr2g$k5g@hobbes.crc.com>#1/1 X-Deja-AN: 473684481 References: <7gkhr7$5kr$1@nnrp1.dejanews.com> Organization: Coleman Research Corporation X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3612.1700 Newsgroups: comp.lang.ada Date: 1999-05-03T00:00:00+00:00 List-Id: phadreus@iname.com wrote in message <7gkhr7$5kr$1@nnrp1.dejanews.com>... > > >How do I test, set, and clear individual bits in an integer >in Ada 83? > How about: package Bit_Ops is function Test (Item : Integer; N : Natural) return Boolean; procedure Set (Item : in out Integer; N : Natural); procedure Clear (Item : in out Integer; N : Natural); end Bit_Ops; package body Bit_Ops is type Bit_Array is array (Natural range 0 .. Integer'Size - 1) of Boolean; pragma Pack (Bit_Array); ----------- -- Clear -- ----------- procedure Clear (Item : in out Integer; N : Natural) is Bits : Bit_Array; for Bits use at Item'Address; begin Bits (N) := False; end Clear; --------- -- Set -- --------- procedure Set (Item : in out Integer; N : Natural) is Bits : Bit_Array; for Bits use at Item'Address; begin Bits (N) := True; end Set; ---------- -- Test -- ---------- function Test (Item : Integer; N : Natural) return Boolean is Bits : Bit_Array; for Bits use at Item'Address; begin return Bits (N); end Test; end Bit_Ops;