View Code of Problem 3700

#include<iostream>
#include<cmath>
using namespace std;
int main(void){
	int n;
	while(cin>>n&&n){
		string b;
		int sum=0,x=0,i=0;
		while(n){
			int k=n%2;
			b+=(k+'0');
			n=n/2;
		}
		for(i=0;i<=b.length()-1;i++){
			if(b[i]!='0') break;
		}
		for(int j=0;j<=i;j++){
			if(b[j]!='0')
				sum+=(pow(2,x));
			x++;
		}
		cout<<sum<<endl;
	}
}

Double click to view unformatted code.


Back to problem 3700