473,769 Members | 6,337 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 #1
12 18624
<sa*********@ya hoo.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*********@yah oo.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**********@y ahoo.com>
wrote:
sa*********@ya hoo.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*********@ya hoo.com> wrote in message news:7c******** *************** ***@posting.goo gle.com...
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="#includ e <stdio.h>%cchar *f=%c%s%c;%cint main(void){prin tf(f,10,34,f,34 ,10,10);return 0;}%c";
int main(void){prin tf(f,10,34,f,34 ,10,10);return 0;}
Nov 13 '05 #5
sa*********@yah oo.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.l earn.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************ **********@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.

--
#include <stdio.h>
char*f="#includ e <stdio.h>%cchar *f=%c%s%c;%cint main(void){prin tf(f,10,34,f,34 ,10,10);return 0;}%c";
int main(void){prin tf(f,10,34,f,34 ,10,10);return 0;}
Nov 13 '05 #7
"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...
Nov 13 '05 #8
Thomas Matthews <Th************ **********@sbcg lobal.net> wrote in message news:<Yv******* ********@newssv r16.news.prodig y.com>...
sa*********@yah oo.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.l earn.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

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

Similar topics

3
5808
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
8982
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
2346
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
4679
by: sudha30 | last post by:
hi please find code to add two numbers only by using bitwise operators
2
2723
by: mahi543 | last post by:
can we write a program in java using bitwise operators to add two numbers
8
5515
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
19130
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
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10222
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...
1
9999
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9866
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
8876
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...
0
6675
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();...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3570
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
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.