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,8c884f53e90ed998 X-Google-Attributes: gid103376,public From: mheaney@ni.net (Matthew Heaney) Subject: Re: Bitwise "OR" for ada Date: 1997/01/10 Message-ID: #1/1 X-Deja-AN: 209097339 references: content-type: text/plain; charset=ISO-8859-1 organization: Estormza Software mime-version: 1.0 newsgroups: comp.lang.ada Date: 1997-01-10T00:00:00+00:00 List-Id: In article , Joel Rudy wrote: >Is there any way to do a bitwise or operation on strings in Ada 83? > >For example => > >clean_String := "AAA"; >template := "LLL"; > >result := clean_string or template; > >Then result would equal "MMM". Here is a way to do it. It does not check that Left and Right are of equal length. function "or" (Left, Right : String) return String is type Bit_Array is array (Positive range 1 .. Left'Size) of Boolean; pragma Pack (Bit_Array); subtype Constrained_String is String (Left'Range); function To_Bit_Array is new Unchecked_Conversion (Constrained_String, Bit_Array); function To_String is new Unchecked_Conversion (Bit_Array, Constrained_String); Left_As_Bit_Array : constant Bit_Array := To_Bit_Array (Left); Right_As_Bit_Array : constant Bit_Array := To_Bit_Array (Right); The_Result_As_Bit_Array : constant Bit_Array := Left_As_Bit_Array or Right_As_Bit_Array; The_Result : constant Constrained_String := To_String (The_Result_As_Bit_Array); begin return The_Result; end; -------------------------------------------------------------------- Matthew Heaney Software Development Consultant (818) 985-1271