edited by
188 views
0 votes
0 votes

Consider the following code, in which $\text{A}$ and $\text{B}$ are arrays indexed from $0$ and $\textsf{lenA}$ and $\textsf{lenB}$ are the numbers of elements in $\text{A}$ and $\text{B}$, respectively.

function foo (A, B, lenA, lenB)  {
    acc = 0;
    
    for i = 0 to (lenA – 1)  {
        acc = A[i] ^ acc;
    }
    print (acc);

    for i = 0 to (lenB – 1)  {
        acc = B[i] ^ acc;
    }
    print (acc);
    
} 

Here, $a^{\wedge} b$ represents the bitwise Exclusive OR function over variables $a$ and $b.$

Given integers $a$ and $b,$ we write them in binary, padded by zeros to the left to make them of equal length. We then apply Exclusive OR to these binary representations bitwise. The operation $a^{\wedge} b$ denotes the integer value obtained by performing bitwise Exclusive OR on the binary values of $a$ and $b.$ For example, $3^{\wedge} 4=011^{\wedge} 100=111=7$, and $9^{\wedge} 5=1001^{\wedge} 0101=1100=12$. The truth table for the Exclusive OR function is provided.

$$ \begin{array}{|c|c|c|} \hline \text{a} & \text{b} & \text{a} ^{\wedge} \text{b}  \\ \hline 0 & 0 & 0 \\ 0 & 1 & 1 \\ 1 & 0 & 1 \\ 1 & 1 & 0 \\ \hline \end{array} $$

Let $\text{A}=[1, 3, 3, 5, 5]$ and $\text{B}=[9, 5, 5, 3, 3, 1]$. What are the two values printed by $\textsf{foo (A, B, 5,6)},$ in order?

edited by

Please log in or register to answer this question.

Related questions