Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- using namespace std;
- string Odwroc(string wyraz)
- {
- string result = "";
- for (int i = wyraz.length()-1; i>=0; i--)
- {
- result += wyraz[i];
- }
- return result;
- }
- string DecToBin(int liczba)
- {
- string result = "";
- while (liczba != 0)
- {
- if (liczba % 2 == 0)
- {
- result += "0";
- }
- else
- {
- result += "1";
- }
- liczba = liczba / 2;
- }
- return Odwroc(result);
- }
- string DecToOct(int liczba)//10 na 8
- {
- string result = "";
- while (liczba != 0)
- {
- result += char(int(liczba%8)+48);
- liczba = liczba / 8;
- }
- return Odwroc(result);
- }
- string DecToHex(int liczba)//10 na 16
- {
- string result = "";
- while (liczba != 0)
- {
- if (liczba%16<10)
- {
- result += char(int(liczba % 16) + 48);
- }
- else
- {
- result += char(int(liczba % 16) + 55);
- }
- liczba = liczba / 16;
- }
- return Odwroc(result);
- }
- int main()
- {
- int liczba;
- cout << "podaj liczba" << endl;
- cin >> liczba;
- cout << DecToBin(liczba) << endl;
- cout << DecToOct(liczba) << endl;
- cout << DecToHex(liczba) << endl;
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement