我有两个数组。
a = [1、2、3、4]
b = [11,22,33,44]
如何对两个数组的各个元素进行异或运算
结果= [10,20,34,40]即1 ^ 11 = 10,2 ^ 22 = 20,依此类推
我尝试过BIT_XOR(x),但是它需要一个数组和xor数组的所有元素。
SELECT BIT_XOR(x) AS bit_xor FROM UNNEST([1, 2, 3, 4]) AS x;
谢谢
答案 0 :(得分:4)
您可以将两个数组“压缩”在一起:
SELECT
ARRAY(
SELECT x ^ b[OFFSET(off)]
FROM UNNEST(a) AS x WITH OFFSET off) AS bit_xor
FROM dataset.table
这会根据元素在两个数组中的偏移量来组合元素。