Re: Addition of 2 numbers without + sign
^^ nope dats does not give da ans..
It does not give for some values..
Try givin a=8 and b=8, or ... 15 and 10 or so..
_____________________
This code works for certain numbers...
Code:
if(a<b)
{
t=a;
a=b;
b=t;
}
printf("%d",a^b);
_____________
EDIT
got it..
Code:
unsigned int add(unsigned int a, unsigned int b)
{ unsigned int c=0, r=0, t=~0;
for(t= ~0;t;t>>=1)
{ r<<=1;
r|=(a^b^c)&1;
c=((a|b)&c|a&b)&1;
a>>=1;
b>>=1;
}
for (t=~0,c=~t;t;t>>=1)
{ c<<= 1;
c|= r&1;
r>>= 1;
} return c;
}
From here
__________________
C2D E8400, MSI P45 Neo-F, Sapphire HD4850, Dell 2409W, OCZ 2*1GB RAM + 1*2GB Transcend + 1*1GB Transcend , Seagate 1TB + 2*Seagate 80GB, 600W SMPS, APC 600VA, Creative EP630, Sennheiser HD202 :)
Last edited by sam_1710; 22-08-2007 at 11:47 PM.
Reason: Automerged Doublepost
|