473,385 Members | 1,375 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,385 software developers and data experts.

how to multiply two integers using bitwise operators

How to mulitply two integer numbers using bitwise operators in C
language.Please reply as early as possible
Nov 13 '05 #1
12 18588
<sa*********@yahoo.com> wrote :
How to mulitply two integer numbers using bitwise operators in C
language.Please reply as early as possible


Emulate the way you learned to do it for decimal numbers in elementary
school.
Nov 13 '05 #2
sa*********@yahoo.com wrote:
How to mulitply two integer numbers using bitwise operators in C
language.Please reply as early as possible


You do know how to sum them, right? Well check this out:

3*4 == 3+3+3+3

3*4 == 4+4+4

Nov 13 '05 #3
On Sun, 21 Sep 2003 14:03:51 GMT, Aggro <sp**********@yahoo.com>
wrote:
sa*********@yahoo.com wrote:
How to mulitply two integer numbers using bitwise operators in C
language.Please reply as early as possible


You do know how to sum them, right? Well check this out:

3*4 == 3+3+3+3

3*4 == 4+4+4


Well that's the easy bit. However + is not a bitwise operator.

Adding using only the bitwise operators is the hard bit of
this problem.

Nick.

Nov 13 '05 #4
<sa*********@yahoo.com> wrote in message news:7c**************************@posting.google.c om...
How to mulitply two integer numbers using bitwise operators in C
language.Please reply as early as possible


Think about how you would do long multiplication in binary.

--
#include <stdio.h>
char*f="#include <stdio.h>%cchar*f=%c%s%c;%cint main(void){printf(f,10,34,f,34,10,10);return 0;}%c";
int main(void){printf(f,10,34,f,34,10,10);return 0;}
Nov 13 '05 #5
sa*********@yahoo.com wrote:
How to mulitply two integer numbers using bitwise operators in C
language.Please reply as early as possible


Can the addition operator be used?

I was taught about left-shift and add, but adding is not a
bitwise operator.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book

Nov 13 '05 #6
"Thomas Matthews" <Th**********************@sbcglobal.net> wrote in message news:YvEbb.728
but adding is not a bitwise operator.


....but it is easy to implement in terms of bitwise operators, as long as you remember the truth table for the full adder.

--
#include <stdio.h>
char*f="#include <stdio.h>%cchar*f=%c%s%c;%cint main(void){printf(f,10,34,f,34,10,10);return 0;}%c";
int main(void){printf(f,10,34,f,34,10,10);return 0;}
Nov 13 '05 #7
"Slartibartfast" <sl******@thhgttg.net> writes:
"Thomas Matthews" <Th**********************@sbcglobal.net> wrote in message news:YvEbb.728
but adding is not a bitwise operator.


...but it is easy to implement in terms of bitwise operators, as long as you remember the truth table for the full adder.


....but the OP reeks of homework...
Nov 13 '05 #8
Thomas Matthews <Th**********************@sbcglobal.net> wrote in message news:<Yv***************@newssvr16.news.prodigy.com >...
sa*********@yahoo.com wrote:
How to mulitply two integer numbers using bitwise operators in C
language.Please reply as early as possible


Can the addition operator be used?

I was taught about left-shift and add, but adding is not a
bitwise operator.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book


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.
Nov 13 '05 #9
<I can't make sense of the attributions, so I snipped them. I suspect there
is one person using two identities.>
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.


A full adder has three inputs: addend, augend and carry in and two outputs:
sum and carry out. Carry in is 0 for the rightmost bit. Make a truth
table and note that the exclusive or is very useful.
Nov 13 '05 #10
osmium wrote:
.... snip ...
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.


A full adder has three inputs: addend, augend and carry in and
two outputs: sum and carry out. Carry in is 0 for the rightmost
bit. Make a truth table and note that the exclusive or is very
useful.


Start with a one-bit adder, where each input and output is a
single bit. Then cascade these to form multiple bit adders.

--
Replies should be to the newsgroup
Chuck Falconer, on vacation.
Nov 13 '05 #11
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

Nov 13 '05 #12
Micah Cowan <mi***@cowan.name> wrote in message news:<m3************@localhost.localdomain>...
"Slartibartfast" <sl******@thhgttg.net> writes:
"Thomas Matthews" <Th**********************@sbcglobal.net> wrote in message news:YvEbb.728
but adding is not a bitwise operator.


...but it is easy to implement in terms of bitwise operators, as long as you remember the truth table for the full adder.


...but the OP reeks of homework...


That's why I didn't say any more. I'm in a good mood so I don't mind
giving a general hint.
Nov 13 '05 #13

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

Similar topics

3
by: sandy_pt_in | last post by:
Hi C guru's can you please tell me how to do multiplication of 2 numbers using bitwize operators?? expecting reply.
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.
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.