473,785 Members | 2,457 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
12 18626
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*********@yah oo.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.na me> wrote in message news:<m3******* *****@localhost .localdomain>.. .
"Slartibartfast " <sl******@thhgt tg.net> writes:
"Thomas Matthews" <Th************ **********@sbcg lobal.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
5809
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
8983
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 programming in straight C, the Win32 API sends windows messages to applications with various settings stored in bit fields, in which case changing the settings of the message is a matter of using the bitwise operators. This was a good practical example of...
1
2347
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 p set to the rightmost n bits of an unsigned char variable y (leaving other bits unchanged). For ex: if x = 10101010 (170 decimal) and y = 10100111 (167 decimal) and n = 3 and p = 6 say then you need to strip off 3 bits of y (111) and...
2
4680
by: sudha30 | last post by:
hi please find code to add two numbers only by using bitwise operators
2
2724
by: mahi543 | last post by:
can we write a program in java using bitwise operators to add two numbers
8
5518
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
19131
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
10325
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8972
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6739
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.