classSolution{public:intgetSum(unsigneda,unsignedb){while(b>0){// Still have carry bits.constunsignedcarry=a&b;// Record the carry bits.a^=b;// ^ works like + without handling carry bits.b=carry<<1;}returna;}};
1 2 3 4 5 6 7 8 910
classSolution{publicintgetSum(inta,intb){while(b!=0){// Still have carry bits.finalintcarry=a&b;// Record the carry bits.a^=b;// ^ works like + without handling carry bits.b=carry<<1;}returna;}}