• It's not a Microsoft thing, and you don't need to analyze and manipulate bits or anything like that - it's just one of the lesser-known features of the XOR function. XOR essentially forms a triangle with two things, such that:

    If C = A XOR B, then B = A XOR C and A = B XOR C.

    Therefore, you can switch two values by just cycling around the circle...

    So...

    Position 1 Position 2 Result of XOR

    A B C (now put this in Position 1)

    C B A (now put this in Position 2)

    C A B (now put this in Position 1)

    B A

    So we've done a nice swap. You don't need to try to complicate matters by understanding WHY xor does this.

    Rob Farley
    LobsterPot Solutions & Adelaide SQL Server User Group
    Company: http://www.lobsterpot.com.au
    Blog: http://blogs.lobsterpot.com.au