Sie sind auf Seite 1von 15

# Project Report

Language of Implementation : C
CODE CONVERSION WIZARD

Number system is a set of symbols that are used to specify any number. The most
commonly used number systems are decimal, binary, octal and hexadecimal. These
number systems are defined on the basis of a radix or base which is the number of
distinct digits in that particular system. The above mentioned number systems are
widely used in digital systems like microprocessors, logic circuits, computers etc. and
therefore knowledge of these is very essential.

In one digital system, different codes may be used for different operations
and it becomes necessary to convert data from one code to another.

## Decimal system has a base 10

binary system has a base 2
octal system has a base 8
hexadecimal system has a base 16

This software allows the user to interconvert between these codes. It is a menu
driven program which allows the user to enter the code as per the choice of
conversion. The code is compared and the control is transferred to the
corresponding function. Then the function asks the user to enter the base code and
the respective transformed code is displayed automatically.

## The program runs continuously. So multiple conversions can be performed by

entering the serial number.

## A systematic method for number conversion

Binary to Decimal

Other number systems use different bases. The binary number system uses base 2, so
the place values of the digits of a binary number correspond to powers of 2. For
example, the value of the binary number 10011 is determined by computing the place
value of each of the digits of the number:

## 2^4 2^3 2^2 2^1 2^0 place values

Binary to Octal

Example:

Example:

Octal to Decimal

The Octal number system uses base 8, so the place values of the digits of octal
number correspond to powers of 8. For example, the value of the octal number 123 is
determined by computing the place value of each of the digits of the number:

## 8^2 8^1 8^0 place values

So (123)8 = (83)10

Octal to Binary

Example:

Example:

## 27.358 = 0001 0111.0111 0100 =

(17.74)16

Example:

The hexadecimal number system uses base 16, so the place values of the digits of a
hexadecimal number correspond to powers of 16. For example, the value of the
hexadecimal number 11F is determined by computing the place value of each of the
digits of the number:

## 16^2 16^1 16^0 place values

So (11F)16 = (287)10

Example:

FLOWCHART
START

## Transfer control to different functions corresponding to user choice of conversion.

1
decbin decoct dechex bindec binoct hexbin

## hexoct binhex octdec octbin Octhex hexdec

YES
Do you want to
continue?

NO

STOP

PROGRAM CODE

#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
void decbin(void);
void decoct(void);
void dechex(void);
void bindec(void);
void binoct(void);
void binhex(void);
void octdec(void);
void octbin(void);
void octhex(void);
void hexdec(void);
void hexbin(void);
void hexoct(void);
void main()
{
int j;

while(1)
{
printf("\n-----------------------CODE CONVERSION WIZARD-----------------------
- ");
printf("\n 1.decimal to binary");
printf("\n 2.decimal to octal");
printf("\n 4.binary to decimal");
printf("\n 5.binary to octal");
printf("\n 7.octal to decimal");
printf("\n 8.octal to binary");
printf("\n 13.exit\n\n");
scanf("%d",&j);
if(j==1)
{
decbin();
}
if(j==2)
{
decoct();
}
if(j==3)
{
dechex();
}
if(j==4)
{
bindec();
}
if(j==5)
{
binoct();
}
if(j==6)
{
binhex();
}
if(j==7)
{
octdec();
}
if(j==8)
{
octbin();
}
if(j==9)
{
octhex();
}
if(j==10)
{
hexdec();
}
if(j==11)
{
hexbin();
}
if(j==12)
{
hexoct();
}
if(j==13)
{
printf("\n\nTHANK YOU FOR USING");
exit(0);
}
}
}
void decbin()
{
int i,n,r[10];
printf("\nenter the decimal number: ");
scanf("%d",&n);
for(i=0;n!=0;i++)
{
r[i]=n%2;
n=n/2;
}
i--;
printf("\nbinary equivalent: ");
for(;i>=0;i--)
{
printf("%d",r[i]);
}
}

void decoct()
{
int i,n,r[10];
printf("\nenter the decimal number: ");
scanf("%d",&n);
for(i=0;n!=0;i++)
{
r[i]=n%8;
n=n/8;
}
i--;
printf("\n octal equivalent: ");
for(;i>=0;i--)
{
printf("%d",r[i]);
}
}

void dechex()
{
int n;
printf("\nenter decimal number: ");
scanf("%d",&n);
}
void bindec()
{
int n,d,i,x;
d=0;
printf("enter binary number: ");
scanf("%d",&n);
for(i=0;n!=0;i++)
{
x=n%10;
d=d+pow(2,i)*x;
n=n/10;
}
printf("\ndecimal equivalent: %d",d);
}

void binoct()
{
int n,d,i,x,r[11];
d=0;
printf("enter binary number");
scanf("%d",&n);
for(i=0;n!=0;i++)
{
x=n%10;
d=d+pow(2,i)*x;
n=n/10;
}
for(i=0;d!=0;i++)
{
r[i]=d%8;
d=d/8;
}
i--;
printf("\n octal equivalent:");
for(;i>=0;i--)
{
printf("%d",r[i]);
}
}

void binhex()
{
int n,d,i,x;
d=0;
printf("enter binary number");
scanf("%d",&n);
for(i=0;n!=0;i++)
{
x=n%10;
d=d+pow(2,i)*x;
n=n/10;
}
}

void octdec()
{
int n,d,i,x;
d=0;
printf("enter octal number");
scanf("%d",&n);
for(i=0;n!=0;i++)
{
x=n%10;
d=d+pow(8,i)*x;
n=n/10;
}
printf("\ndecimal value=%d",d);
}

void octbin()
{
int n,d,i,x,r[11];
d=0;
printf("enter octal number");
scanf("%d",&n);
for(i=0;n!=0;i++)
{
x=n%10;
d=d+pow(8,i)*x;
n=n/10;
}
for(i=0;d!=0;i++)
{
r[i]=d%2;
d=d/2;
}
i--;
printf("\nbinary equivalent:");
for(;i>=0;i--)
{
printf("%d",r[i]);
}
}
void octhex()
{
int n,d,i,x;
d=0;
printf("enter octal number");
scanf("%d",&n);
for(i=0;n!=0;i++)
{
x=n%10;
d=d+pow(8,i)*x;
n=n/10;
}
}

void hexdec()
{
int a;//debugging
int i,j,n[11],d=0;
char arr[11];
scanf("%x",&a);
printf("\ndecimal equivalent:%d",a);

/*
for(i=0;arr[i]!='\0';i++);
i--;
for(j=0;i!=0;i--,j++)
{

if (arr[i]>='0'&& arr[i]<='9')
{
n[i]=arr[i]-'0';
}
else if (arr[i]>='a'&& arr[i]<='f')
{
n[i]=arr[i]-'a'+10;
}
else if (arr[i]>='A'&& arr[i]<='F')
{
n[i]=arr[i]-'A'+10;
}
d=d+pow(16,j)*n[i];
}
printf("\ndecimal equivalent:%d",d);
*/
}

void hexbin()
{ int a;
int temp;
int i=0;
int n[11],d=0,r[11];
int arr[11];

scanf("%x",&a);
temp=a;
printf("\nBinary:");
for(;a>0;i++)
{
arr[i]=(char)a%2;

a=a/2;
}

for(i=i-1;i>=0;i--)
{
printf("%d",arr[i]);
}

/* for(i=0;arr[i]!='\0';i++)
{
if (arr[i]>='0'&& arr[i]<='9')
{
n[i]=arr[i]-'0';
}
else if (arr[i]>='a'&& arr[i]<='f')
{
n[i]=arr[i]-'a'+10;
}
else if (arr[i]>='A'&& arr[i]<='F')
{
n[i]=arr[i]-'A'+10;
}
d=d+pow(16,i)*n[i];
}
for(i=0;n!=0;i++)

{
r[i]=d%2;
d=d/2;
}
i--;
printf("\nbinary equivalent:");
for(;i>=0;i--)
{
printf("%d",r[i]);
}
*/
}
void hexoct()
{
int a;
int temp=0;
int i=0;
int n[11],d=0,r[11];
char arr[11];
scanf("%x",&a);

temp=a;
printf("\nOctal:");
for(;a>0;i++)
{
arr[i]=(char)a%8;
a=a/8;
}

for(i=i-1;i>=0;i--)
{
printf("%d",arr[i]);
}

/*
for(i=0;arr[i]!='\0';i++)
{
if (arr[i]>='0'&& arr[i]<='9')
{
n[i]=arr[i]-'0';
}
if (arr[i]>='a'&& arr[i]<='f')
{
n[i]=arr[i]-'a'+10;
}
if (arr[i]>='A'&& arr[i]<='F')
{
n[i]=arr[i]-'A'+10;
}
d=d+pow(16,i)*n[i];
}

for(i=0;d!=0;i++)
{
r[i]=d%8;
d=d/8;
}
i--;
printf("\n octal equivalent:");
for(;i>=0;i--)
{
printf("%d",r[i]);
}
*/
}