473,387 Members | 1,844 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

mulitiplication using bitwise operators

Hi C guru's
can you please tell me how to do multiplication of 2 numbers using
bitwize operators?? expecting reply.
Nov 13 '05 #1
3 5772
sa*********@yahoo.com wrote:
can you please tell me how to do multiplication of 2 numbers using
bitwize operators?? expecting reply.


To multiply:

[1] Initialize product to zero.
[2] While multiplicand is greater than zero, add (see below)
multiplier to product and decrement multiplicand.

To add:

[1] Initialize sum to augend
[2] Exclusive OR sum and addend
[3] AND addend and sum, shift this result left one position
[4] Result from [2] replaces sum
[5] Result from [3] replaces addend
[6] If addend isn't zero, continue from [2]
--
Morris Dovey
West Des Moines, Iowa USA
C links at http://www.iedu.com/c

Nov 13 '05 #2
sa*********@yahoo.com writes:
Hi C guru's
can you please tell me how to do multiplication of 2 numbers using
bitwize operators?? expecting reply.


Why would you want to do that?

If this is homework, we won't do it for you. If you have some other
reason to want to do this, you need to (1) explain why you can't just
use the "*" operator, and (2) show us some C code so we can help you
with it.

Off the top of my head, I'm sure it's possible, but it's probably
pretty difficult.

--
Keith Thompson (The_Other_Keith) ks*@cts.com <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
Nov 13 '05 #3
On Fri, 19 Sep 2003 01:32:06 -0500, Morris Dovey <mr*****@iedu.com>
wrote:
sa*********@yahoo.com wrote:
can you please tell me how to do multiplication of 2 numbers using
bitwize operators?? expecting reply.
To multiply:

For nonnegative (or unsigned) integers only. Otherwise, add more
complexity. (Well, not add, that's not bitwise. Shift in?)
[1] Initialize product to zero.
[2] While multiplicand is greater than zero, add (see below)
multiplier to product and decrement multiplicand.
Decrement is not bitwise. Change that to add ~0U.
Or to the specialized algorithm: loop changing all trailing zero bits
to one and (then) the last one to zero.

Or, even better, use "Russian peasant":
[2] While multiplicand is greater than zero,
[2A] if low bit of multiplicand is set, add multiplier to product.
[2B] (always) shift multiplier left and multiplicand right.
To add:

[1] Initialize sum to augend
[2] Exclusive OR sum and addend
[3] AND addend and sum, shift this result left one position
[4] Result from [2] replaces sum
[5] Result from [3] replaces addend
[6] If addend isn't zero, continue from [2]


You could do full-adder logic with carry-save, and only complete the
ripples at the end. But I don't think it's feasible to do look-ahead.
Or at least not worth the trouble.

drHTHtOP :-)

- David.Thompson1 at worldnet.att.net
Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: sandy_pt_in | last post by:
How to mulitply two integer numbers using bitwise operators in C language.Please reply as early as possible
6
by: jas_lx | last post by:
The basic understanding of what bitwise operators (& ^ | >> << ) comes fairly simple, as long as one has a fundamental understanding of bits, bytes and binary. Having done some Win32...
1
by: Harika | last post by:
Hi all Any one of you would give me small c program using bitwise operators to below given statement. A function setbits(x,p,n,y) that returns x with the n bits that begin at position...
2
by: sudha30 | last post by:
hi please find code to add two numbers only by using bitwise operators
2
by: mahi543 | last post by:
can we write a program in java using bitwise operators to add two numbers
8
by: Aftabpasha | last post by:
Is it possible to find (integer) result of divison of a number by 7 by using Bitwise operators only? Please give a method to do so. Thank you.
14
by: Aftabpasha | last post by:
Is it possible to perform all arithmetic operations (+,-,*,/) using Bitwise operations only. Please consider signed numbers also. Thank You.
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.