comp.lang.ada
 help / color / mirror / Atom feed
From: mheaney@ni.net (Matthew Heaney)
Subject: Re: Bitwise "OR" for ada
Date: 1997/01/10
Date: 1997-01-10T00:00:00+00:00	[thread overview]
Message-ID: <mheaney-ya023280001001971924530001@news.ni.net> (raw)
In-Reply-To: Pine.OSF.3.91.970109130027.809A-100000@osf1.gmu.edu


In article <Pine.OSF.3.91.970109130027.809A-100000@osf1.gmu.edu>, Joel Rudy
<jrudy@osf1.gmu.edu> 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
<mailto:matthew_heaney@acm.org>
(818) 985-1271




      reply	other threads:[~1997-01-10  0:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-01-09  0:00 Bitwise "OR" for ada Joel Rudy
1997-01-10  0:00 ` Matthew Heaney [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox