<div dir="ltr"><div class="gmail_default" style="font-family:monospace,monospace;font-size:small;color:rgb(0,0,255)">Hi all,</div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small;color:rgb(0,0,255)"><br></div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small;color:rgb(0,0,255)">We all know the bitwise operators: & (and), | (or), ^ (xor), and ~ (not). We know how they work with numbers:</div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small;color:rgb(0,0,255)"><br></div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small;color:rgb(0,0,255)">420 ^ 502</div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small;color:rgb(0,0,255)"><br></div><div class="gmail_default"><font color="#0000ff" face="monospace, monospace">110100100<br class="gmail-Apple-interchange-newline"><span style="color:rgb(0,0,255);font-family:monospace,monospace;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">111110110</span></font><br></div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small;color:rgb(0,0,255)">== XOR ==</div><div class="gmail_default"><font color="#0000ff" face="monospace, monospace">001010010</font><br></div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small;color:rgb(0,0,255)">= 82</div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small;color:rgb(0,0,255)"><br></div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small;color:rgb(0,0,255)">But it might be useful in some cases to (let's say) xor a string (or bytestring):</div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small;color:rgb(0,0,255)"><br></div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small;color:rgb(0,0,255)">HELLO ^ world</div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small;color:rgb(0,0,255)"><br></div><div class="gmail_default"><font color="#0000ff" face="monospace, monospace">01001000 01000101 01001100 01001100 01001111</font><br></div><div class="gmail_default"><font color="#0000ff" face="monospace, monospace">01110111 01101111 01110010 01101100 01100100<br></font></div><div class="gmail_default"><font color="#0000ff" face="monospace, monospace">=================== XOR ====================</font></div><div class="gmail_default"><font color="#0000ff" face="monospace, monospace">00111111 00101010 00111110 00100000 00101011</font><br></div><div class="gmail_default"><font color="#0000ff" face="monospace, monospace">= ?*> +</font></div><div class="gmail_default"><font color="#0000ff" face="monospace, monospace"><br></font></div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small;color:rgb(0,0,255)">Currently, that's done with this expression for strings:</div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small;color:rgb(0,0,255)"><br></div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small;color:rgb(0,0,255)">    >>> ''.join(chr(ord(a) ^ ord(b)) for a, b in zip('HELLO', 'world'))</div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small;color:rgb(0,0,255)">    '?*> +'</div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small;color:rgb(0,0,255)"><br></div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small;color:rgb(0,0,255)">and this expression for bytestrings:</div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small;color:rgb(0,0,255)"><br></div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small;color:rgb(0,0,255)">    >>> bytes(a ^ b for a, b in zip(b'HELLO', b'world'))</div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small;color:rgb(0,0,255)">    b'?*> +'</div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small;color:rgb(0,0,255)"><br></div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small;color:rgb(0,0,255)">It would be much more convenient, however, to allow a simple xor of a string:</div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small;color:rgb(0,0,255)"><br></div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small;color:rgb(0,0,255)">    >>> 'HELLO' ^ 'world'</div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small;color:rgb(0,0,255)">    '?*> +'</div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small;color:rgb(0,0,255)"><br></div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small;color:rgb(0,0,255)">or bytestring:</div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small;color:rgb(0,0,255)"><br></div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small;color:rgb(0,0,255)">    >>> b'HELLO' ^ b'world'</div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small;color:rgb(0,0,255)">    b'?*> +'</div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small;color:rgb(0,0,255)"><br></div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small;color:rgb(0,0,255)">(All of this applies to other bitwise operators, of course.)</div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small;color:rgb(0,0,255)">Compatibility issues are a no-brainer - currently, bitwise operators for strings raise TypeErrors.</div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small;color:rgb(0,0,255)"><br></div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small;color:rgb(0,0,255)">Thanks.</div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small;color:rgb(0,0,255)"><br></div><div class="gmail_default" style="font-family:monospace,monospace;font-size:small;color:rgb(0,0,255)">Suggesting,</div><div><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><font color="#0000ff" face="monospace, monospace">Ken<div class="gmail_default" style="font-family:monospace,monospace;font-size:small;color:rgb(0,0,255);display:inline">​ Hilton​</div>;</font><br></div></div></div></div></div></div></div></div></div>
</div>