Great! Glad that we agree that ($B,$A)=($A,$B) is FAR superior the XOR trick! Clarity is an important aspect of software engineering.

XOR is fundamental to data encryption and error correction codes. But for the most part, you won't need to use this in your normal code!!

This is a bit off topic as this is 'C' Code, but just to show you another tricky way of using XOR in a low level sub. This is basically "modem code" as it looks like the gibberish that would result from an unsync'd modem!!

Low level C has stuff like this, but almost no Perl code should have it! Heck the raw assembly code is easier to understand this this critter below, but this idiomatic good C code. enjoy.

/* flip all bits except between range defined by startBit and numBits to left*/ /* bit numbering like: 7 6 5 4 3 2 1 0 */ inline unsigned short flipNotInRange (unsigned short in, int startBit, + int numBits) { unsigned short result; result =(~in) ^ (~((unsigned short) ~0<<numBits )<< startBit); return result; }

In reply to Re^5: is index faster than regexp for fixed text token? by Marshall
in thread is index faster than regexp for fixed text token? by sflitman

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.