RWalib C Array Library User Guide > Logical Operations > alibXor
  

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

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