Logo

Programming-Idioms

Write in a new byte array c the xor result of byte arrays a and b.

a and b have the same size.
Implementation
Ruby

Implementation edit is for fixing errors and enhancing with metadata. Please do not replace the code below with a different implementation.

Instead of changing the code of the snippet, consider creating another Ruby implementation.

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
c := make([]byte, len(a))
for i := range a {
	c[i] = a[i] ^ b[i]
}
c = bytes([aa ^ bb for aa, bb in zip(a, b)])
SetLength(c, Length(a));
for i := Low(a) to High(a) do c[i] := a[i] xor b[i];
var c T
for i := range a {
	c[i] = a[i] ^ b[i]
}
local c = {}
for i=1,#a do
	c[i] = string.char(string.byte(a, i) ~ string.byte(b, i))
end
c = table.concat(c)
let c: Vec<_> = a.iter().zip(b).map(|(x, y)| x ^ y).collect();
use iso_fortran_env, only : int8
integer(kind=int8), dimension(:) :: a, b, c
! Assign values to a and b
c = ieor(a,b)
const c = Uint8Array.from(a, (v, i) => v ^ b[i])
using System.Linq;
var c = a.Zip(b, (l, r) => (byte)(l ^ r)).ToArray();
byte[] c = new byte[a.length];
for (int i = 0; i < a.length; i++) {
  c[i] = (byte) (a[i] ^ b[i]);
}
use feature 'bitwise';
$c = $a ^. $b;
(map '(vector (unsigned-byte 8)) #'logxor a b)