online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
#include <cstdint> #include <iostream> #include <vector> using namespace std; pair<uint32_t, uint8_t> division(uint32_t a, uint8_t b) { // this is doable by bitwise logic uint8_t arr[4] = {(a)%256U, (a/256U)%256U, (a/(256U*256U))%256U, (a/(256U*256U*256U))%256U}; uint8_t res[4] = {0, 0, 0, 0}; uint8_t c = 0; uint8_t result_pos = 32; bool carry = false; while (result_pos) { result_pos -= 1; carry = (c >= 0x80); c = c*2 + (arr[result_pos/8]>>(result_pos%8))%2; // bitwise logic //cout << int(c) << ' '; if (carry || c >= b) { c -= b; //cout << 1 << endl; res[result_pos/8] |= (1<<(result_pos%8)); // bitwise logic } //else // cout << 0 << endl; } return pair<uint32_t,uint8_t>(res[0]+res[1]*256U+res[2]*(256U*256U)+res[3]*(256U*256U*256U), c); } int main() { uint32_t a, _b; // _b to read as integer instead of char cin >> a >> _b; uint8_t b = _b; pair<uint32_t, uint8_t> res = division(a, b); cout << "result:" << res.first << " remainder:" << int(res.second); 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