Witam jak moge napisac program z zamiany liczby w systemie 2 na 16 ? Do tej pory udalo mi sie tylko zrobic z 16 na 2 i nie wiem jak zabrac sie za odwrotna sytuacje. Tutaj kod z 16 na 2.
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int i,j,pom;
string x, zbior="0123456789ABCDEF";
do
{
cout<< "Podaj liczbe w systemie 16 ";
cin>> x;
for(i=0;i<x.size();i++)
{
for(j=0;j<zbior.size();j++)
{
if(x[i]==zbior[j])
{
pom++;
break;
}
}
}
}while(x[i]==zbior[j]);
for(i=0;i<x.size();i++)
{
switch(x[i])
{
case '0':
cout<< "0000 ";
break;
case '1':
cout<< "0001 ";
break;
case '2':
cout<< "0010 ";
break;
case '3':
cout<< "0011 ";
break;
case '4':
cout<< "0100 ";
break;
case '5':
cout<< "0101 ";
break;
case '6':
cout<< "0110 ";
break;
case '7':
cout<< "0111 ";
break;
case '8':
cout<< "1000 ";
break;
case '9':
cout<< "1001 ";
break;
case 'A':
cout<< "1010 ";
break;
case 'B':
cout<< "1011 ";
break;
case 'C':
cout<< "1110 ";
break;
case 'D':
cout<< "1101 ";
break;
case 'E':
cout<< "1110";
break;
case 'F':
cout<< "1111 ";
break;
}
}
getch();
return 0;
}