RWalib C Array Library User Guide > Logical Operations > alibAnd
  

alibAnd
Applies the & operator element-wise to scalar or array arguments. For general array-based code, this routine is most commonly used as a logical-and 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 AND.
Prototypes
void alibAndb( wvlong m, wvlong n, UCHAR *p, UCHAR *q, UCHAR *r )
void alibAnds( wvlong m, wvlong n, short *p, short *q, short *r )
void alibAndi( wvlong m, wvlong n, int *p, int *q, int *r )
void alibAndl( 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-and of the two operands, element-wise. For operands containing only 0's and 1's (e.g., arrays produced by relational operations) the bitwise-and is functionally equivalent to the logical-and. alibAnd 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,1}, b2[5]={0,1,1,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 and' of array b0 and the scalar b3=2" );
      alibinit( NULL, NULL, NULL, NULL );
      alibAndb( 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" );
      alibAndb( 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-and is the same as their logical-and" );
      alibAndb( 5, 5, b1, b2, b );
      alibPrintArrayb( 1, 1, 1, 5, b, NULL );
   printf( "\n\n now do the same operation in-place on b2" );
      alibAndb( 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 and' of array b0 and the scalar b3=2
 
   0   0   2   2   0
 
 now reverse operands and do the same operation in-place
 
   0   0   2   2   0
 
 show the 5-element input arrays b1 and b2
 
   0   1   0   1   1
 
   0   1   1   0   1
 
 since the two input arrays contain only 0's and 1's, 
 their bitwise-and is the same as their logical-and
 
   0   1   0   0   1
 
 now do the same operation in-place on b2
 
   0   1   0   0   1

Version 2017.1
Copyright © 2019, Rogue Wave Software, Inc. All Rights Reserved.