Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- string dec2bin(int);
- string dec2oct(int);
- string dec2hex(int);
- string dec2n(int, int);
- int main()
- {
- int y, p;
- cin>>y>>p;
- cout<<dec2bin(y)<<" "<<dec2oct(y)<<" "<<dec2hex(y);
- return 0;
- }
- string dec2bin(int x) {
- string w;
- while(x) {
- w=char(x%2+'0')+w;
- x/=2;
- }
- return w;
- }
- string dec2oct(int x) {
- string w;
- while(x) {
- w=char(x%8+'0')+w;
- x/=8;
- }
- return w;
- }
- string dec2hex(int x) {
- char t[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
- string w;
- while(x) {
- w=t[x%16]+w;
- x/=16;
- }
- return w;
- }
- string dec2n(int x, int n) {
- char t[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
- string w;
- while(x) {
- w=t[x%16]+w;
- x/=n;
- }
- return w;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement