In article <11**********************@a26g2000pre.googlegroups .com>,

<ra******@gmail.comwrote:

>count the bits required to be altered while swaping values a and b

The answer may be ill-defined. If a temporary value is used,

the the number of bits required to be altered to set that

temporary to a certain value would depend on what was in

the temporary to start with, which is unknown if the temporary

is in automatic storage.

There is also the question of how to count the alteration of bits.

If a particular bit gets altered twice, then is that a count of 2

(two alterations), or a count of 1 (one bit altered) ?

Is the requirement to come up with a formula that expresses the

number of bits required to be altered to swap two values? Or is

the requirement to come up with a program that would count the

bits required to be altered to swap two values that are inputs?

Or are the two values given ahead of time?

What do we know about the types of the two values a and b?

Are they integral types? Are they potentially floating point

numbers? Are they potentially of mixed type, one integral

and one floating point?

What are we to do about the problem that "bits" are a matter

of representation (which is not completely defined in C),

whereas "values" are independant of representation? For example,

the answer might be different if the C implementation happens

to be using two's complement to represent values when the programmer

is expecting one's complement representation instead.

--

Programming is what happens while you're busy making other plans.