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=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,bd45e29f9dafca87 X-Google-Attributes: gid103376,public From: "DuckE" Subject: Re: bitwise comparators Date: 2000/01/16 Message-ID: <38829638.0@news.pacifier.com>#1/1 X-Deja-AN: 573603581 References: <3880D375.7E363123@hotmail.com> X-Priority: 3 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 X-Trace: 16 Jan 2000 20:10:32 PST, 216.65.140.109 X-MSMail-Priority: Normal Reply-To: "DuckE" Newsgroups: comp.lang.ada Date: 2000-01-16T00:00:00+00:00 List-Id: Alexander Van Hecke wrote in message news:3880D375.7E363123@hotmail.com... > hello, > > I want to do the following : > OK_to_proceed : BOOLEAN := FALSE; > data : Unsigned_8; > > while (not OK_to_proceed) loop > -- do stuff > OK_to_proceed := (data BITWISE AND 2#1#); > end loop; > > so I want to exit the loop if bit one of data is set, but I don't know > what the bitwise and is! Caution: You've caught me in a "chatty" mood. As others have responded, if Unsigned_8 is a modular type, you can use the "AND" operator and just change your code to read: while (not OK_to_proceed) loop -- do stuff OK_to_proceed := (data and 2#1#) /= 0; end loop; Note: in Ada booleans and integer or modular types are two different critters so you cannot assign an integer to a boolean. I'd also like to point out that the "while" construct you are using is common for 'C' or Pascal, but in Ada you could use a "loop" construct with "exit when" loop -- do stuff exit when (data and 2#1#) /= 0; end loop; And eliminate the need for an OK_to_proceed variable. Of course this is a matter of style preference. The other thing I'd like to point out is with Ada you can explicity map bits within memory using representation clauses, for example: type status_register is record data_ready : boolean; end record; for status_register use record data_ready at 0 range 0..0; end record; for status_register'size use 8; register : status_register; for register'address use -- fill in the address of the register here And then the loop becomes: loop -- do stuff exit when register.data_ready end loop; Which eliminates explicit bit masking altogether. Of course you may have to use a volatile pragma to make sure the value gets loaded for each test. SteveD > > alex >