Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include "iostream"
- #include "windows.h"
- using namespace std;
- void dec_to_bin(int dec)
- {
- if (dec >= 2)
- dec_to_bin(dec / 2);
- cout << dec % 2;
- }
- void dec_to_oct(int dec)
- {
- if (dec >= 8)
- dec_to_oct(dec / 8);
- cout << dec % 8;
- }
- void dec_to_hex(int dec)
- {
- if (dec == 0)
- return;
- int rem = dec % 16;
- dec /= 16;
- dec_to_hex(dec);
- if (rem > 9)
- cout << (char)(rem - 10 + 'A');
- else
- cout << rem;
- }
- int main()
- {
- while (1)
- {
- int dec;
- cout << "Enter value: ";
- cin >> dec;
- cout << dec << "[10] -> ";
- dec_to_bin(dec);
- cout << "[2]" << endl;
- cout << dec << "[10] -> ";
- dec_to_oct(dec);
- cout << "[8]" << endl;
- cout << dec << "[10] -> ";
- dec_to_hex(dec);
- cout << "[16]" << endl << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment