RWalib C Array Library User Guide > Logical Operations > alibOr
  

alibOr
Applies the | operator element-wise to scalar or array arguments. For general array-based code, this routine is most commonly used as a logical-or between arrays of 0's and 1's, e.g., arrays produced by relational operations. The PV-WAVE API for this routine is the operator OR.
Prototypes
void alibOrb( wvlong m, wvlong n, UCHAR *p, UCHAR *q, UCHAR *r )
void alibOrs( wvlong m, wvlong n, short *p, short *q, short *r )
void alibOri( wvlong m, wvlong n, int *p, int *q, int *r )
void alibOrl( wvlong m, wvlong n, wvlong *p, wvlong *q, wvlong *r )
Parameters
m — (Input) The number of elements in the first array operand. A value of 0 indicates that the first operand is a scalar.
n — (Input) The number of elements in the second array operand. A value of 0 indicates that the second operand is a scalar. If both operands are arrays then n must equal m.
*p — (Input) The pointer to the first operand.
*q — (Input) The pointer to the second operand.
*r — (Input/Output) The destination array. On return, array r contains the bitwise-or of the two operands, element-wise. For operands containing only 0's and 1's (e.g., arrays produced by relational operations) the bitwise-or is functionally equivalent to the logical-or. alibOr can be done in-place, i.e., r can equal p or q.
Example
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "alib.h"
void main() {
   /* make up some input data for the examples */
      UCHAR b0[5]={0,1,2,3,4}, b1[5]={0,1,0,1,0}, b2[5]={0,1,0,0,1}, b3=2;
   /* make an output array */
   UCHAR *b;
   b = (UCHAR*)malloc(5*sizeof(UCHAR));
   printf( "\n\n show the 5-element input array b0" );
      alibPrintArrayb( 1, 1, 1, 5, b0, NULL );
   printf( "\n\n find the bitwise-or of array b0 and the scalar b3=2" );
      alibinit( NULL, NULL, NULL, NULL );
      alibOrb( 5, 0, b0, &b3, b );
      alibPrintArrayb( 1, 1, 1, 5, b, NULL );
   printf( "\n\n now reverse operands and do the same operation in-place" );
      alibOrb( 0, 5, &b3, b0, b0 );
      alibPrintArrayb( 1, 1, 1, 5, b0, NULL );
   printf( "\n\n show the 5-element input arrays b1 and b2" );
      alibPrintArrayb( 1, 1, 1, 5, b1, NULL );
      alibPrintArrayb( 1, 1, 1, 5, b2, NULL );
   printf( "\n\n since the two input arrays contain only 0's and 1's, \n" );
   printf( " their bitwise-or is the same as their logical-or" );
      alibOrb( 5, 5, b1, b2, b );
      alibPrintArrayb( 1, 1, 1, 5, b, NULL );
   printf( "\n\n now do the same operation in-place on b2" );
      alibOrb( 5, 5, b1, b2, b2 );
      alibPrintArrayb( 1, 1, 1, 5, b2, NULL );
}
 
Output:
 
show the 5-element input array b0
 
   0   1   2   3   4
 
 find the bitwise-or of array b0 and the scalar b3=2
 
   2   3   2   3   6
 
 now reverse operands and do the same operation in-place
 
   2   3   2   3   6
 
 show the 5-element input arrays b1 and b2
 
   0   1   0   1   0
 
   0   1   0   0   1
 
 since the two input arrays contain only 0's and 1's, 
 their bitwise-or is the same as their logical-or
 
   0   1   0   1   1
 
 now do the same operation in-place on b2
 
   0   1   0   1   1

Version 2017.0
Copyright © 2017, Rogue Wave Software, Inc. All Rights Reserved.