sa*********@yahoo.com wrote:
Condition was to use only bitwise operators. Eventhough can you tell
me that method you know, using add operation.I will scratch my head to
get somthing out of it.
Addition can be viewed as a sequence of bitwise operations.
Exclusive or-ing the addend and augend yields all of the partial
sum bits; while and-ing the addend and augend yields all of the
carry bits. Shift the carry bits left one position.
Put the partial sum in the addend.
If there are no 1's in the carry bits, then you're done and the
result of the addition is in the addend.
Otherwise put the carry bits in the augend and repeat.
There are other ways to get the job done; but this is the easiest
to describe. 8^)
It's fairly easy to back into subtraction by negating and adding;
and a (very) simplistic multiplication can be implemented using
the addition algorithm to repeatedly add one of the factors to
the product and addition of -1 to the other factor.
Division can be done as a bitwise successive approximation; but
requires development of a bitwise magnitude comparison (left as
an exercise for the student :)
--
Morris Dovey
West Des Moines, Iowa USA
C links at
http://www.iedu.com/c