C/C++ >> help me PLZ....!
Posted by fatma on 04:25:00 03-15-2003
how can I implement a function that takes an integer (x) and returns the negation (-x)

NOTE:just use { ! , ^ , -->--> , [ This Message was edited by: dxprog on 2003-03-15 10:15 ]
Posted by fatma on 23:52:00 03-15-2003
thank you dxprog ..

but multiplying operation is NOT ALLOWED in this question .. look , in this question I'm dealing with binary numbers (ex. [00000111 = 7]) so ,asume that x=00000111 ,
and we should by this function return (11111001 = -7)by using only the operations{!,+,&,^,-->,~,|}..

thank you again for triying ...
Posted by Yjo on 07:46:00 03-16-2003
I have *no* idea why you would want to do this unless it's some (stupid) assignment or other...
but:
i'll assume youre using 16 or 32 bit signed integers, which use two's compliment encoding for negative numbers, which is simply the one's compliment+1.
i.e.:
Code:
int negate(int i)
{
i=~i;
return ++i;
}
Posted by dxprog on 08:19:00 03-16-2003
Sorry, didn't realize that. Thought maybe you were some young whipper snapper or something [addsig]
Posted by Smerdyakov on 19:40:00 03-16-2003
Yjo, why did you answer if you know it's an assignment?
Posted by fatma on 23:31:00 03-16-2003
yjo .. thank you for helpping ..
Posted by jjthebear on 08:00:00 03-24-2003
fatma - operators are whatever you make them. I can make the Code:
#include <math.h>
double negation(double negateThis) {
return -1*abs(negateThis);
}
Posted by Yjo on 07:26:00 03-25-2003
I think it's great that you've recently discovered c++ and are excited about it, but...
RTFT (thread)
Posted by jjthebear on 12:37:00 03-25-2003
Who exactly are you talking to dude?