Click here to Skip to main content
16,005,552 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: '^' operator Pin
LiYS5-Jul-05 0:04
LiYS5-Jul-05 0:04 
GeneralRe: '^' operator Pin
Bob Stanneveld5-Jul-05 0:31
Bob Stanneveld5-Jul-05 0:31 
GeneralRe: '^' operator Pin
Bob Stanneveld5-Jul-05 0:36
Bob Stanneveld5-Jul-05 0:36 
GeneralRe: '^' operator Pin
toxcct5-Jul-05 1:02
toxcct5-Jul-05 1:02 
GeneralRe: '^' operator Pin
Bob Stanneveld5-Jul-05 2:09
Bob Stanneveld5-Jul-05 2:09 
GeneralRe: '^' operator Pin
Toby Opferman5-Jul-05 8:32
Toby Opferman5-Jul-05 8:32 
GeneralRe: '^' operator Pin
David Crow5-Jul-05 5:05
David Crow5-Jul-05 5:05 
GeneralRe: '^' operator Pin
Toby Opferman5-Jul-05 6:45
Toby Opferman5-Jul-05 6:45 
The logic is this:

A = A (operation) B
B = A (operation Inverse) B
A = A (operation Inverse) B


If you do one operation and then two inverse operations you will have swapped the numbers. The "xor" operator is actually the inverse of itself, so that's why it works the way it does.

For example if you use +, - is the inverse:
A = 10, B = 20
A = A + B (10 + 20 = 30)
B = A - B (30 - 20 = 10)
A = A - B (30 - 10 = 20)
A = 20, B = 10

A = 10, B = 20
A = A * B (10*20 = 200)
B = A / B (200/20 = 10)
A = A / B (200/10 = 20)
A = 20, B = 10


A = 10, B = 20
A = A ^ B (10 ^ 20 = 30)
B = A ^ B (30 ^ 20 = 10)
A = A ^ B (30 ^ 10 = 20)
A = 20, B = 10

xor is also communiative, so it didn't matter the order you have A or B when doing ^. This XOR swap was generally used by small processors which memory operations were slow, so 3 XOR instructions could be faster. That actually used to be the method of setting registers to 0 as well, XOR reg, reg as it was faster than a MOV reg, 0.






8bc7c0ec02c0e404c0cc0680f7018827ebee
GeneralRe: '^' operator Pin
Toby Opferman5-Jul-05 6:50
Toby Opferman5-Jul-05 6:50 
GeneralRe: '^' operator Pin
PJ Arends5-Jul-05 9:02
professionalPJ Arends5-Jul-05 9:02 
QuestionTo delete (remove) wizard created functions via IDE of VC++ 2003 ? Pin
Maxwell Chen4-Jul-05 22:29
Maxwell Chen4-Jul-05 22:29 
Generalchanging color of my form in vc++ Pin
smartymanav4-Jul-05 21:45
smartymanav4-Jul-05 21:45 
GeneralRe: changing color of my form in vc++ Pin
Alex Korchemniy4-Jul-05 21:54
Alex Korchemniy4-Jul-05 21:54 
GeneralRe: changing color of my form in vc++ Pin
David Spain5-Jul-05 18:43
David Spain5-Jul-05 18:43 
GeneralContext menu on Tree Pin
--------------------------------4-Jul-05 21:21
suss--------------------------------4-Jul-05 21:21 
GeneralRe: Context menu on Tree Pin
Bert [Otherside82] Derijckere5-Jul-05 0:31
Bert [Otherside82] Derijckere5-Jul-05 0:31 
Generalcreating modeless dialog box Pin
sayup4-Jul-05 20:41
sayup4-Jul-05 20:41 
GeneralRe: creating modeless dialog box Pin
2249174-Jul-05 20:57
2249174-Jul-05 20:57 
GeneralRe: creating modeless dialog box Pin
Cedric Moonen4-Jul-05 20:59
Cedric Moonen4-Jul-05 20:59 
GeneralRe: creating modeless dialog box Pin
2249174-Jul-05 21:05
2249174-Jul-05 21:05 
GeneralRe: creating modeless dialog box Pin
Cedric Moonen4-Jul-05 21:24
Cedric Moonen4-Jul-05 21:24 
GeneralRe: creating modeless dialog box Pin
sayup5-Jul-05 2:37
sayup5-Jul-05 2:37 
GeneralSetActivePage of CPropertySheet Pin
GeloSoft4-Jul-05 20:35
GeloSoft4-Jul-05 20:35 
GeneralRe: SetActivePage of CPropertySheet Pin
PJ Arends4-Jul-05 21:10
professionalPJ Arends4-Jul-05 21:10 
Generalusing CMap Pin
laiju4-Jul-05 18:34
laiju4-Jul-05 18:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.