Number System Conversion
//This is a C++ program for inter conversion between binary, octal, hexadecimal and //decimal number systems
#include<iostream.h>
#include<conio.h>
int main()
{
int Binary[8], Octal[10],HexaINT[10],no, store, i,j,k,l, mod, dif;
char Arr[7]={"ABCDEF"}, HexaChar[10];
cout<<"Enter a decimal no";
cin>>no;
store=no;
for(i=0; store!=0; store/=2, i++)
{
*(Binary+i)= store%2;
}
store=no;
for(j=0; store!=0; store/=8, j++)
{
*(Octal+j)= store%8;
}
store=no;
for(k=0,l=0; store!=0; store/=16)
{ mod=store%16;
if(mod<10)
{ *(HexaINT+k)= mod;
k++;
}
else if(mod>=10)
{ dif=mod-10;
*(HexaChar+l)= *(Arr+dif) ;
l++;
}
}
store=no;
cout<<"Binary Representation="<<"\n";
for(i--; i>=0; i--)
{
cout<<*(Binary+i);
}
cout<<"\n\n";
cout<<"Octal form="<<"\n";
for(j--; j>=0; j--)
{
cout<<*(Octal+j);
}
cout<<"\n\n";
cout<<"Hexadecimal Representation="<<"\n";
for(k--,l--; store!=0; k--,l--,store/=16)
{ if((store%16)>=10)
cout<<*(HexaChar+l);
else
cout<<*(HexaINT+k);
}
getch();
}
OUTPUT :
