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,FREEMAIL_FROM, INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,aac6281ad4fb7480 X-Google-Attributes: gid103376,public From: Mats Weber Subject: Re: Bit Manipulations Date: 1999/12/21 Message-ID: <385F7055.7450E3A7@mail.com>#1/1 X-Deja-AN: 563370445 Content-Transfer-Encoding: 7bit References: X-Accept-Language: en Content-Type: text/plain; charset=us-ascii X-Complaints-To: usenet@sunrise.ch X-Trace: news1.sunrise.ch 945778774 5108 195.141.231.162 (21 Dec 1999 12:19:34 GMT) Organization: sunrise communications ag Mime-Version: 1.0 NNTP-Posting-Date: 21 Dec 1999 12:19:34 GMT Newsgroups: comp.lang.ada Date: 1999-12-21T12:19:34+00:00 List-Id: generic type T is private; function bitwise_and (left, right : T) return T; function bitwise_and (left, right : T) return T is type bit_array_t is array (1 .. T'Size) of Boolean; pragma Pack (Bit_Array_T); function to_t is new unchecked_conversion(bit_array_t, t); function to_bit_Array is new unchecked_conversion(t, bit_array_t); begin return to_t(to_bit_array(left) and to_bit_array(right)); end; Then create "and" operators for the types you need, e.g.: type my_int is range -34 .. 2222; function "and" is new bitwise_and(character); function "and" is new bitwise_and(integer); function "and" is new bitwise_and(my_int); > For instance, I get a byte from a hardware port and want to mast off the > parity bit ( 16#07F#). > > I want to do... > > char_data := char_data AND 16#07F# or, simpler: if character'pos(char_data) > 127 then char_data := character'val(character'pos(char_data) - 128); end if;