Skip navigation

This solution is for the book I am currently reading. All of my notes and solutions are available at Google Code.

Here is my work for problem 2.10:

To show how the ring properties of ^ can be useful, consider the following
void implace_swap( int *x, int *y ) {
  *x = *x ^ *y; /* Step 1 */
  *y = *x ^ *y; /* Step 2 */
  *x = *x ^ *y; /* Step 3 */
Starting with values a and b in the locations pointed to by x and y,
respectively, fill in the table that follows giving the values stored
at the two locations after each step of the procedure. Use the ring
properties to show that the desired effect is achieved. Recall that
every element is its own additive inverse (that is, a ^ a = 0).

Step           *x                  *y
Initially       a                   b
Step 1         a^b                  b
Step 2         a^b            (a^b)^b=(b^b)^a=a
Step 3    (a^b)^a=(a^a)^b=b         a


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: