Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- #include <vector>
- void convert(int num, int base)
- {
- std::vector<int> buffer;
- while(num>0)
- {
- buffer.push_back(num%base);
- num = num / base;
- }
- if (base==2)
- std::cout << "Rappresentazione binaria = ";
- if (base==8)
- std::cout << "Rappresentazione ottale = ";
- if (base==16)
- std::cout << "Rappresentazione esadecimale = ";
- for (int i=buffer.size()-1; i>=0; i--)
- {
- if (buffer[i]>=10)
- std::cout << char(buffer[i]+55);
- else
- std::cout << buffer[i];
- }
- }
- int main()
- {
- // Richiesta del numero da convertire
- std::cout << "Immettere intero in rappresentazione decimale \n";
- int num;
- std::cin >> num;
- convert(num,2);
- std::cout << std::endl;
- convert(num,8);
- std::cout << std::endl;
- convert(num,16);
- std::cout << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement