function stringXor(string, position){ var out = (parseInt(string, 2) ^ 1<<(string.length - position - 1)).toString(2); while (out.length < string.length) out = "0" + out; return out; } alert(stringXor("0110001", 2));