473,799 Members | 3,197 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can we perfom multiplication programatically without using + or * operator.


How can we perfom multiplication programatically without using + or *
operator.
Can any one help out in this one.

Jagadeesh.

May 29 '06 #1
11 4881
mj********@yaho o.co.in wrote:
How can we perfom multiplication programatically without using + or *
operator.
Can any one help out in this one.


If you conceptualise the numerical values in a binary format, then left
shifting the value by N is similar to multiplying the value by 2^N.

May 29 '06 #2
mj********@yaho o.co.in said:
How can we perfom multiplication programatically without using + or *
operator.


Addition can be done by using ^ (xor), & (and), and << (left shift) in the
proper way.

Multiplication is repeated addition (i.e. addition in a loop).

Alternatively, you can double and halve, if you're careful in the case of an
odd number. Note that doubling will require using addition as described
above (since you are not allowed the * operator).

That's enough of a hint - now do your own homework.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
May 29 '06 #3
Ico
mj********@yaho o.co.in wrote:

How can we perfom multiplication programatically without using + or *
operator.
Can any one help out in this one.


#include <stdio.h>

int mult(int a, int b)
{
int c = 0;
while(a--) c -= b;
return -c;
}

int main(void)
{
int a = 5;
int b = 6;

printf("%d x %d = %d\n", a, b, mult(a, b));

return 0;
}

--
:wq
^X^Cy^K^X^C^C^C ^C
May 29 '06 #4
Ico said:
mj********@yaho o.co.in wrote:

How can we perfom multiplication programatically without using + or *
operator.
Can any one help out in this one.


#include <stdio.h>

int mult(int a, int b)
{
int c = 0;
while(a--) c -= b;
return -c;
}


Very funny. :-)

But I suspect his teacher is trying to get him to find out how computers do
addition and multiplication "under the hood" (because a computer does not
have the luxury of a magic wand we call '*').

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
May 29 '06 #5

Richard Heathfield wrote:
Ico said:
mj********@yaho o.co.in wrote:

How can we perfom multiplication programatically without using + or *
operator.
Can any one help out in this one.


#include <stdio.h>

int mult(int a, int b)
{
int c = 0;
while(a--) c -= b;
return -c;
}


Very funny. :-)

But I suspect his teacher is trying to get him to find out how computers do
addition and multiplication "under the hood" (because a computer does not
have the luxury of a magic wand we call '*').

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)


Hehehehehehe!

Totally irrelevent but I thought your magic wand comment was funny :-)

May 29 '06 #6
newbie wrote:
Richard Heathfield wrote:

.... snip ...
But I suspect his teacher is trying to get him to find out how computers do
addition and multiplication "under the hood" (because a computer does not
have the luxury of a magic wand we call '*').


Hehehehehehe!

Totally irrelevent but I thought your magic wand comment was funny :-)


Have you been exposing yourself to nitrous oxide? ;)

May 29 '06 #7
mj********@yaho o.co.in wrote:
How can we perfom multiplication programatically without using + or *
operator.


#include <stdio.h>

int main(void)
{
double m1=4.0, m2=5.0;

printf("%f times %f equals %f.\n", m1, m2, m1/(1.0/m2));

return 0;
}

HTH; HAND.

Richard
May 29 '06 #8
Ico
Richard Bos <rl*@hoekstra-uitgeverij.nl> wrote:
mj********@yaho o.co.in wrote:
How can we perfom multiplication programatically without using + or *
operator.


#include <stdio.h>

int main(void)
{
double m1=4.0, m2=5.0;

printf("%f times %f equals %f.\n", m1, m2, m1/(1.0/m2));

return 0;
}


Taking stupid assignments literally, that must be some kind of dutch
humor :)

--
:wq
^X^Cy^K^X^C^C^C ^C
May 29 '06 #9
mj********@yaho o.co.in wrote:
#
#
#
# How can we perfom multiplication programatically without using + or *
# operator.
# Can any one help out in this one.

Any good text on computation theory should include the multiplication
of radix one integers.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
Mention something out of a Charleton Heston movie, and suddenly
everybody's a theology scholar.
May 29 '06 #10

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

Similar topics

11
2553
by: Michael Bader | last post by:
Hi, I'm currently working on a matrix multiplication code (matrix times matrix), and have come along some interesting/confusing results concerning the running time of the (apparently) same algorithm, when implemented in C or C++. I noticed that the implementation in C is faster by a factor of 2.5 compared to a identical(?) C++-implementation. The basic algorithm in C is:
1
2829
by: akickdoe22 | last post by:
Please help me finish this program. i have completed the addition and the subtraction parts, but i am stuck on the multiplication and division. any suggestions, hints, code, anyhting. it's not a true large int calculator, the numbers entered are at max 100 intergers. CODE SO FAR: #include<iostream> //libraries limited to #include<string> using namespace std;
54
8380
by: Andy | last post by:
Hi, I don't know if this is the correct group to post this, but when I multiply a huge floating point value by a really small (non-zero) floating point value, I get 0 (zero) for the result. This creates a big hole in a 32-bit timer routine I wrote. Questions. 1. Why does this happen? 2. Is there C macros/functions I can call to tell me when two non-zero numbers are multiplied and the
87
11249
by: Vijay Kumar R Zanvar | last post by:
Hi, Why multiplication of pointers is not allowed? Till now I only know this, but not the reason why! PS: As a rule, I searched the FAQ, but could not find an answer. -- Vijay Kumar R Zanvar
31
3151
by: Pesso | last post by:
What happens if you multiple two integers and the result overflows the MAX_INT in C? Is there a way to trap the condition when it happens?
6
16444
by: amitsoni.1984 | last post by:
Hi, Is there any direct function for matrix multiplication in Python or any of its packages? or do we have to multiply element by element? Thank you, Amit
4
1600
by: siluomm | last post by:
hi.....i am btech2nd year student.please send me the programming of multiplication of two array using operator overloading concept in c++
11
1911
by: Holgerson | last post by:
Hi everybody, what I try to do is to implement an operator* into NRVec in such a way, that I can perform an operation like number*vector rather than vector*number which is easy. Any ideas? Thanks a lot, Holger
3
2197
by: =?Utf-8?B?TWFya19C?= | last post by:
The following is working for me but I want to include numbers in scientific notation. public double Evaluate( string expr ) { const string Num = @"(\-?\d+\.?\d*|\-?\.\d+)" Regex reMulDiv = new Regex(Num + @"\s*()\s*" + Num); other stuff:
0
9685
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9538
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
10470
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
7561
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
6803
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
5459
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5583
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4135
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
3751
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.