text: Subtract 1 without arithmetic operators | C ++ code to subtract one from a given number ; Flip all the set bits until we find a 1 ; Flip the rightmost 1 bit ; Driver code
code: #include <iostream> NEW_LINE using namespace std ; int subtractOne ( int x ) { int m = 1 ; while ( ! ( x & m ) ) { x = x ^ m ; m <<= 1 ; } x = x ^ m ; return x ; } int main ( ) { cout << subtractOne ( 13 ) << endl ; return 0 ; }