for (int i = 31; i>=0; i--) { cout << ((n>>i) & 1); } cout << endl; } int fun(unsigned int x) { int n = 0; while ((x + 1)) { dec2Bin(x); n++; x = x | (x + 1); } return n; } int main() { int n=2014; int a=fun(n); cout << a; system("Pause"); return 0; }