This language bar is your friend. Select your favorite languages!
Select your favorite languages :
- Or search :
std::array<std::byte, a.size()> c;
for (auto ia = a.begin(), ib = b.begin(); auto & rc : c) {
rc = *ia++ ^ *ib++;
}
std::byte xor operator requires C++17.
range for init-statement requires C++20.
range for init-statement requires C++20.
int n = a.length;
byte c[] = new byte[n];
range(0, n).forEach(x -> {
c[x] = (byte) (a[x] ^ b[x]);
});
local c = {}
for i=1,#a do
c[i] = string.char(string.byte(a, i) ~ string.byte(b, i))
end
c = table.concat(c)
Uses strings as byte arrays, since Lua strings are raw bytes.
Creates c as a table, appends to it, and concats it into a string, because appending to a string means rehashing it every time, which becomes a real problem for large strings.
Creates c as a table, appends to it, and concats it into a string, because appending to a string means rehashing it every time, which becomes a real problem for large strings.
$c = $a ^. $b;
perl has strings rather than byte arrays, but its built-in xor operator (^) has undefined behaviour when the operands aren't numbers. The 'bitwise' feature enables a operator (^.) that works bitwise on the bytes within strings.