Created
July 21, 2017 22:07
-
-
Save gluschenko/cabf006ed38d536784a568df822c0c89 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
using namespace std; | |
void trace(int n) | |
{ | |
int nmem = n; | |
vector<int> M; | |
while(n > 0) | |
{ | |
int bit = n % 2 == 0 ? 0 : 1; | |
M.push_back(bit); | |
n /= 2; | |
} | |
for(int i = M.size(); i < 32; i++){ | |
cout << 0; | |
} | |
for(int i = M.size() - 1; i >= 0; --i){ | |
cout << M[i]; | |
} | |
cout << " = " << nmem << "\n"; | |
} | |
int main(int argc, char** argv) { | |
int x = 2147483647; | |
trace(x); | |
x = x >> 16; | |
trace(x); | |
x = x << 16; | |
trace(x); | |
x = x >> 1; | |
trace(x); | |
x = x >> 1; | |
trace(x); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment