# Hello Pls solve my problem..How to add,subtract,multiply & divide 2 numbers?without..

Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last
• 01-24-2008
chottachatri
Hello Pls solve my problem..How to add,subtract,multiply & divide 2 numbers?without..
Hello,
how can you add,subtract,multiply and divide 2 numbers without using Arithmatic operators (+,/,*,-,%,++,--)

i have a basic idea that it can be done using bitwise operator but how that i don't know! can anybody provide me a solution?please?
• 01-24-2008
Elysia
And why would you do that?
• 01-24-2008
chottachatri
it's my question! what will i do or not that's a different thing
if you know you may answer if you don't then fine, even i don't know just wait like me. Let the other big heads come and give the solution
• 01-24-2008
rogster001
i think you should chill your beans a bit matey
• 01-24-2008
chottachatri
Ok fine! but is this a question to ask?
what will you do by that?? what will i do? i can do nothing from that it's just for my information purpose i want to know
• 01-24-2008
invinciblevn
It's better if you ask clear question to get a clear answer.
• 01-24-2008
This is an example of the answer. It's called Bit Shifting. In this example YELLOW, etc., are just defines for numbers, the << is the bit shifting operator, and the 4 is the number of bits that are being shifted. Google that, and you'll be good to go. Might be in the forum FAQ, as well.

Quote:

textattr(YELLOW+(RED<<4));
• 01-24-2008
chottachatri
Quote:

textattr(YELLOW+(RED<<4));

and what for have you used + operator? i dont want any arithmatic operator. Just use bitwise operators like &,~,|,^(And,Complement,Or,XOR)
• 01-24-2008
Elysia
If you explained why, perhaps someone could better easily find a solution.
Emulating all the arithmetic operators isn't easy and more complex that it actually solves, so hence the question again, why?
• 01-24-2008
Quote:

Originally Posted by chottachatri
and what for have you used + operator? i dont want any arithmatic operator. Just use bitwise operators like &,~,|,^(And,Complement,Or,XOR)

I wasn't giving a full and complete answer to the question, I believe that was obvious since I mentioned the need to google & check our FAQ.

The process of learning becomes quite trivialized if you answer every student's question, fully. They have brains, they are problem solvers; a few clues in the right direction is sufficient.
• 01-24-2008
laserlight
I shall unashamedly link you to the Wikipedia article on binary adders.
• 01-24-2008
foxman
Quote:

how can you add,subtract,multiply and divide 2 numbers without using Arithmatic operators (+,/,*,-,%,++,--)
Code:

```int add(int a, int b) {   __asm   {       push eax       mov eax, a       add b, eax       pop eax   }   return b; }```
No + sign used...

By the way, the "++" operator is just a way to say "x = x + 1". It's an addition and an affection operator all in one.

With the link laserlight posted, you now should have some idea about how to implement addition. Once you done that, other operators will mostly be cake.
• 01-24-2008
laserlight
Quote:

No + sign used...
But you are using an arithmetic instruction. If indeed the list of what is forbidden was exhaustive, then implementing add() with operator+= would be even simpler, heheh.

Quote:

It's an addition and an affection operator all in one.
I have never heard of "affection" used in this context. Do you mean "assignment" instead?
• 01-24-2008
Elysia
Yeah, it's just the assembly equalient of the C/C++ code. I'd call that cheating ;)
• 01-24-2008
foxman
Hey, he asked not to use any arithmetic operator, and i don't see any use of it in the code i gave. ;)

Quote:

I have never heard of "affection" used in this context. Do you mean "assignment" instead?
My mistake, i did mean assignment. Doesn't make a lots of sense: i didn't write correctly the word i was thinking of and even that word doesn't exist in English (it's not my first language).
Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last