Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- int main()
- {
- int n,cont=0,cop,nr=0,i,cif;
- cout<<"Numarul in baza 2 este... ";
- cin>>n;
- cop=n;
- while (cop)
- {
- cop=cop/10;
- cont++;
- }
- for (i=0;i<cont;i++)
- {
- cif=n%10;
- n=n/10;
- nr=nr+cif*pow(2,i);
- }
- cout<<nr;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement