Last active
August 29, 2015 14:02
-
-
Save enedil/fc9a1ef01bfab7cd07c2 to your computer and use it in GitHub Desktop.
This file contains 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 <cmath> | |
int to_decimal(int n, int num); | |
int from_decimal(int n, int num); | |
int main() | |
{ | |
std::ios_base::sync_with_stdio(0); | |
int P; | |
std::cin >> P; | |
std::cout << from_decimal(to_decimal(P, 2), 2) << "\n"; | |
} | |
int to_decimal(int n, int num) | |
{ | |
int res = 0; | |
for (int i = 0; n; i++) | |
{ | |
res += (n % 10) * pow(num, i); | |
n /= 10; | |
} | |
return res; | |
} | |
int from_decimal(int n, int num) | |
{ | |
int res = 0; | |
for (int i = 0; n; i++) | |
{ | |
res += (n % num) * pow (10, i); | |
n /= num; | |
} | |
return res; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment