* Bitwise "OR" for ada
@ 1997-01-09 0:00 Joel Rudy
1997-01-10 0:00 ` Matthew Heaney
0 siblings, 1 reply; 2+ messages in thread
From: Joel Rudy @ 1997-01-09 0:00 UTC (permalink / raw)
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".
I know that or will give you a set, so the real result would equal "AL".
I am more interested in the bitwise or, not the or that is provided with Ada.
Thanks for your help.
Joel Rudy
PS -- please respond to the group or to me personally at
joel.rudy@comm.hq.af.mil.
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Bitwise "OR" for ada
1997-01-09 0:00 Bitwise "OR" for ada Joel Rudy
@ 1997-01-10 0:00 ` Matthew Heaney
0 siblings, 0 replies; 2+ messages in thread
From: Matthew Heaney @ 1997-01-10 0:00 UTC (permalink / raw)
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1997-01-10 0:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-01-09 0:00 Bitwise "OR" for ada Joel Rudy
1997-01-10 0:00 ` Matthew Heaney
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox