Cattle customer network _ Alternative additions

// alternative addition, can not use arithmetic operators 
int addAB ( int A, int B) {
     // Write code here Wallpaper 
    int XOR, and;
     the while (B =! 0 ) 
    { 
        XOR = ( int ) (A ^ B); / / exclusive oR operation with the same result of the addition of two numbers, the carry does not include
         //   1010
         // + 1101
         @ = 0111 10111 XOR result, without the carry bit 
        and = ( int ) ((a & B) << . 1 ); // calculation result of adding two numbers and the same binary (0/1 binary result),
         // calculation result is 1000, the fourth addition generates a carry, a left 10000, and exclusive oR phase plus:
         //  0111
         // +10000
         // = 10111 
        A = XOR; 
        B = and; // the left to a calculation result B (because it is binary, adding to the previous one), then an exclusive OR (equivalent to addition), until no carry the. 
    }
     Return A; 
}

 

Guess you like

Origin www.cnblogs.com/dabai56/p/10955412.html