Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- using namespace std;
- int main(int argc, char *argv[])
- {
- if (argc < 3)
- {
- cout << "Uzycie: " << argv[0] << " <liczba DEC> <baza>" << endl;
- cout << "Przyklad: " << argv[0] << " 254 16" << endl;
- return 0;
- }
- if (atoi(argv[2]) < 2 or atoi(argv[2]) > 36)
- {
- cout << "Baza musi byc miedzy 2 a 36!" << endl;
- return 0;
- }
- vector<char> cyfry;
- int baza = atoi(argv[2]);
- cout << "cyfry systemu " << argv[2] << ":" << endl;
- for (int i = 0; i < baza; i++)
- {
- if (i < 10)
- {
- cyfry.push_back((char)('0' + i));
- }
- else
- {
- cyfry.push_back((char)('A' + i - 10));
- }
- cout << cyfry[i] << " ";
- }
- cout << endl << endl;
- int liczba = atoi(argv[1]);
- string hex = "";
- int temp = liczba;
- vector<int> div;
- int i = 0;
- while (temp > 0)
- {
- div.push_back(temp % baza);
- temp -= div[i];
- temp /= baza;
- i++;
- }
- for (int i = div.size() - 1; i >= 0; i--)
- {
- hex += cyfry[div[i]];
- }
- cout << liczba << "{10} = " << hex << "{" << baza << "}" << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment