online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
#include <iostream> using namespace std; inline int bit(int a, int n) {if(n > 31) return 0; return (a & ( 1 << n )) >> n; } int main(){ int A = 19; int B = 7; int X = 0; int carryover = 0; int aCurrent, aNext, bCurrent, bNext; for(int i = 0; i < 32; i++){ aCurrent = bit(A, i); bCurrent = bit(B, i); aNext = bit(A, i + 1); bNext = bit(B, i + 1); cout<<"A["<<i<<"] = "<<aCurrent<<", "<<"B["<<i<<"] = "<<bCurrent<<", carryover = "<<carryover<<endl; if(aCurrent == 0 && bCurrent == 0){ if(carryover) {X = -1; break;} if(aNext != bNext){ cout<<"\tX["<<i<<"] must be 1"<<endl; X += 1 << i; } else cout<<"\tX["<<i<<"] will be 0"<<endl; carryover = 0; } else if(aCurrent == 0 && bCurrent == 1){ if(!carryover) {X = -1; break;} if(aNext == bNext){ cout<<"\tX["<<i<<"] must be 1"<<endl; X += 1 << i; } else cout<<"\tX["<<i<<"] will be 0"<<endl; carryover = 1; } else if(aCurrent == 1 && bCurrent == 0){ if(!carryover) {X = -1; break;} if(aNext != bNext){ cout<<"\tX["<<i<<"] must be 1"<<endl; X += 1 << i; carryover = 1; } else { cout<<"\tX["<<i<<"] will be 0"<<endl; carryover = 0; } } else if(aCurrent == 1 && bCurrent == 1){ if(carryover) {X = -1; break;} if(aNext != bNext){ cout<<"\tX["<<i<<"] must be 1"<<endl; X += 1 << i; carryover = 1; } else { cout<<"\tX["<<i<<"] will be 0"<<endl; carryover = 0; } } } if(X != -1) cout<<"X = "<<X<<endl; else cout<<"X doesnt exist"<<endl; return 0; }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue