128 lines
2.2 KiB
C++
128 lines
2.2 KiB
C++
#include <iostream>
|
|
|
|
using namespace std;
|
|
|
|
void hex() {
|
|
int i,k,n,m;
|
|
|
|
cout << "Podaj liczbe dziesietna: ";
|
|
cin >> n;
|
|
int *a = new int[n];
|
|
|
|
m=n;
|
|
|
|
i = 1;
|
|
while(m>=1) {
|
|
a[i] = m % 16;
|
|
m = m / 16;
|
|
i++;
|
|
}
|
|
|
|
k = i - 1;
|
|
|
|
cout << endl;
|
|
|
|
for(i = 1; i <= k; i++) {
|
|
if(i % 4 == 0) {
|
|
cout << " ";
|
|
}
|
|
if(a[i] > 9) {
|
|
if(a[i] == 10) {
|
|
cout << "A";
|
|
}
|
|
if(a[i] == 11) {
|
|
cout << "B";
|
|
}
|
|
if(a[i] == 12) {
|
|
cout << "C";
|
|
}
|
|
if(a[i] == 13) {
|
|
cout << "D";
|
|
}
|
|
if(a[i] == 14) {
|
|
cout << "E";
|
|
}
|
|
if(a[i] == 15) {
|
|
cout << "F";
|
|
}
|
|
}
|
|
else {
|
|
cout << a[i];
|
|
}
|
|
|
|
}
|
|
|
|
cout << endl;
|
|
|
|
delete [] a;
|
|
}
|
|
|
|
void octal() {
|
|
int i,k,n,m;
|
|
|
|
cout << "Podaj liczbe dziesietna: ";
|
|
cin >> n;
|
|
int *a = new int[n];
|
|
|
|
m=n;
|
|
|
|
i = 1;
|
|
while(m>=1) {
|
|
a[i] = m % 8;
|
|
cout << a[i] << " ";
|
|
m = m / 8;
|
|
i++;
|
|
}
|
|
|
|
k = i - 1;
|
|
|
|
cout << endl << "K = " << k << endl;
|
|
|
|
for(i = 1; i <= k; i++) {
|
|
if(i % 3 == 0) {
|
|
cout << " " << a[i];
|
|
}
|
|
else {
|
|
cout << a[i];
|
|
}
|
|
}
|
|
|
|
cout << endl;
|
|
|
|
delete [] a;
|
|
}
|
|
|
|
int main() {
|
|
char choice;
|
|
|
|
cout << "Wybierz system :" << endl;
|
|
cout << "1. Binarny" << endl;
|
|
cout << "2. Oktalny" << endl;
|
|
cout << "3. Decymanalny" << endl;
|
|
cout << "4. Hexadecimalny" << endl;
|
|
cout << "Podaj swoj wybor: ";
|
|
|
|
cin >> choice;
|
|
|
|
switch(choice) {
|
|
case '1':
|
|
cout << "Wybierasz system binarny." << endl;
|
|
break;
|
|
case '2':
|
|
system("cls");
|
|
cout << "Wybierasz system oktalny." << endl;
|
|
octal();
|
|
case '3':
|
|
cout << "Wybierasz system dziesietny." << endl;
|
|
break;
|
|
case '4':
|
|
system("cls");
|
|
cout << "Wybierasz system szesnastkowy." << endl;
|
|
hex();
|
|
default:
|
|
break;
|
|
}
|
|
|
|
system("pause");
|
|
return 0;
|
|
} |