473,806 Members | 2,748 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
11 4884
posted:

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

Jagadeesh.

Seems like you need a book on digital electronics and boolean logic.
-Tomás

May 29 '06 #11
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 '*').

For "computer", read "lowest level of computing hardware". That level
usually doesn't have multiplication as a primitive operation. Go any higher
(say, the processor as a whole) and you'll find that most computers do have it.

<musing>
Doing this in C is a silly exercise, by the way, because the assumption that
C's set of primitive operations (minus + and *) closely resembles that of
the hardware is less and less commonly valid (or relevant). This line of
thinking, incidentally, is also what makes people invest in clever bit
tricks when they start prematurely optimizing.

I'd think a good exposition in microcode would be more relevant. Either that
or, if you really think it's relevant that people find a general
multiplication algorithm on their own (why?), a very basic set of operators
and statements with which to do it, but not just "go do it in C without * or +".
</musing>

S.
May 29 '06 #12

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

Similar topics

11
2554
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
2831
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
8384
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
11255
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
3152
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
16447
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
1601
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
2198
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
9719
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
9599
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
10624
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
10371
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
10111
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
9193
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
6877
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
5546
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...
1
4330
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

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.