FF Logo

Formal Formulations

===========================

Exchanging Values
via
Three 'Exclusive-Or' Operations

--------------------------

Introduction

The elementary approach for
exchanging the contents of two memory registers,
A and B,
is to declare a third register, say,
C,
and then:
  1. Copy the contents of A into C;
  2. Copy the contents of B into A;
  3. Copy the contents of C into B;
This is a fine solution,
provided that creating another register is cheap.
However, if registers are expensive and CPU cycles are cheap,
then an alternative approach is available.

When three consecutative "Exclusive-Or" operations
are performed on the contents of two memory registers,
the effect is to exchange the contents of the two memory registers.

--------------------------

Title

Proof

The proof consists for three sections,
one for each of the "Exclusive-Or" Assignments.

--------------------------

First Assignment

Title

Title

continue onto the Second Assignment...

--------------------------

Exclusive Or Demonstration

Enter a value for A, B, and then click Exchange.

A
B
A = A xor B;( B = B )
( A = A )B = A xor B;
A = A xor B;( B = B )

--------------------------

Exchanging Values
[ Introduction ][ Theorem ]
[ First Assignment ][ Second Assignment ][ Third Assignment ]

Other Links
[ Non-Numerical Arithmetic ][ Boundary Mathematics ]
[ Java Meets the Laws of Form ][ Form and Substance ]

--------------------------
Copyright © 1996. Formal Formulations. ~ ~ ~ Send e-Mail to comment@formal.com.
###### hits since 96/10/13. Updated 96/10/13. hits since 96/10/13. Updated 96/10/13.