Showing posts with label Decimal to Octal Conversion. Show all posts
Showing posts with label Decimal to Octal Conversion. Show all posts

Monday, 21 July 2014

Write a Program in C++ Which Convert Decimal Number into Octal and Hexadecimal

1. Decimal to Binary Conversion
2. Decimal to Octal Conversion
3. Decimal to Hexadecimal Conversion


Structure of the Problem Requirements 


In this Problem we convert a number into its equivalent Binary, Octal and Hexadecimal Numbers. To convert a numbers into its equivalent we divide the given number with its base for example to convert into Octal divide with 8 and for Hexadecimal divide it with 16. For Hexadecimal Further more condition is applied which show the alphabet. 

Source Code    


#include<iostream>
#include<conio.h>
using namespace std;

int main()
{

int num;
cout<<"\n\n\n ************** NUMBER CONVERSION ************** \n\n\n";
cout<<" \n Enter Number = ";
cin>>num;
int digit=num;
int n=num;
cout<<"  \n \n In Binary = ";
while(num>0)
{
int remminder;
remminder=num%2;
cout<<remminder;
num=num/2;
}
cout<<" \n \n In Octal = ";
while(digit>0)
{
int r;
r=digit%8;
cout<<r;
digit=digit/8;
}
cout<<" \n \n In Hexa Decimal= ";
while(n>0)
{
int remminderm;
remminderm=n%16;
if(remminderm<9)
{
cout<<remminderm;
}
else
if(remminderm==10)
{
cout<<"A";
}
else
if(remminderm==11)
{
cout<<" B ";
}
else
if(remminderm==12)
{
cout<<" C ";
}
else
if(remminderm==13)
{
cout<<" D ";
}
else
if(remminderm==14)
{
cout<< " E ";
}
else
if(remminderm==15)
{
cout<< " F ";
}
n=n/16;
}
return 0;
}

Output of the Program 

Decimal to Octal and Hexadecimal Conversion
Convert Decimal into Octal and Hexadecimal