"" "
@ param a: The first integer
@ param b: The second integer
@ return: The sum of a and b
"" "
Def aplusb (self, a, b) :
# write your code here, try to do it without arithmetic operators.
If a==0: return b
If b==0: return a
C=1
D=1
C=a ^ b
D=(a& B) & lt; <1
Return the self. Aplusb (c, d)
Writing, in the treatment of the [100-100] will display memory problems, such as Taoist what reason
CodePudding user response:
While (b!=0) {
Int _a=^ b;
Int _b=(a & amp; B) & lt; <1;
A=_a;
B=_b;
}
return a;
CodePudding user response:
A c language, very essence, post
//addInt. CPP: defines the entry point of the console application,
//
# include "stdafx. H"
Int AddInt (int a, int b)
{
A char * c=(char *);
Return (int) & amp; C [b];
}
Int main ()
{
Int b=AddInt (1, 4);
return 0;
}
CodePudding user response:
A + b can be divided into three steps to understand, such as a=3, b=21, a binary representation is 0011, b binary is 0010, so not consider carry the result of a + b is 0001,
2, consider only carry, the result is 0011 + 0010=0010
3, turn it into a carry left one, 00100
4, will be exclusive or 00100 to 0001, 00101, namely the decimal under equal to 5
5, the end of the
CodePudding user response:
Thinking is the same, why python this code can't deal with [100100], this group of dataCodePudding user response:
Try this:A, b=map (int, input (). The split (" "))
Print (a + b)