#include< stdio.h >
#include< stdlib.h >
#include< string.h >
int Sa_24Bit();
int Sa_8Bit();
int Sa_Negtive();
int Sa_48Bit();
int Sa_ConBin(int iSa_Int,double fSa_Frac);
int Sa_Convert(int iSa_Num,int iSa_Bits);
int main()
{
int iSa_Choi;
printf("\t1. Integer To 24-Bit Binary Convertion.\n\t2. String To 8-Bit ASCII Value Convertion.\n\t3. Negative Number To Binary Convertion\n\t4. Fractional Number To 48-Bit Floating Point\n");
scanf("%d",&iSa_Choi);
if(iSa_Choi==1)
Sa_24Bit();
else if(iSa_Choi==2)
Sa_8Bit();
else if(iSa_Choi==3)
Sa_Negtive();
else if(iSa_Choi==4)
Sa_48Bit();
else
exit(0);
}
// FUNCTION TO GET THE INTEGER VALUE
int Sa_24Bit()
{
int iSa_Num;
printf("Enter Your Integer Value : ");
scanf("%d",&iSa_Num);
if (iSa_Num<0)
{
printf("invalid input\n");
exit(0);
}
printf("Corresponding Binary Number is : ");
Sa_Convert(iSa_Num,6);
printf("\n");
return 0;
}
// FUNCTION TO GET THE STRING
int Sa_8Bit()
{
char cSa_Str[20];
int iSa_cnt;
printf("Enter Your String : ");
scanf("%s",cSa_Str);
for(iSa_cnt=0;iSa_cnt
Sa_Convert(cSa_Str[iSa_cnt],2);
printf(" ");
}
printf("\n");
return 0;
}
// FUNCTION TO GET THE NEGATIVE NUMBER
int Sa_Negtive()
{
int iSa_Num;
printf("Enter Negative Integer Value : ");
scanf("%d",&iSa_Num);
if (iSa_Num>0)
{
printf("invalid input\n");
exit(0);
}
printf("Corresponding 2's Complement is : ");
Sa_Convert(iSa_Num,8);
printf("\n");
return 0;
}
// FUNCTION TO GET FRACTIONAL VALUE
int Sa_48Bit()
{
int iSa_Int;
double fSa_Num,fSa_Frac;
printf("Enter a Fractional Value : ");
scanf("%lf",&fSa_Num);
if(fSa_Num<0)
{
printf("Sign Bit : 1\n");
fSa_Num*=-1;
}
else
printf("Sign Bit : 0\n");
iSa_Int=fSa_Num;
fSa_Frac=fSa_Num-iSa_Int;
Sa_ConBin(iSa_Int,fSa_Frac);
}
// FUNCTION TO CONVERT FRACTION
int Sa_ConBin(int iSa_Int,double fSa_Frac)
{
unsigned int iSa_Temp1=1<<31,iSa_Temp2=1<<10;
int iSa_incr=-1,iSa_Array[68],iSa_cnt,iSa_temp,iSa_Num;
while(iSa_Temp1)
{
if(iSa_Temp1 & iSa_Int)
iSa_Array[++iSa_incr]=1;
else
if(iSa_incr!=-1)
iSa_Array[++iSa_incr]=0;
iSa_Temp1>>=1;
}
printf("Mantissa Part : ");
iSa_Num=127+iSa_incr;
while(iSa_Temp2)
{
if(iSa_Temp2 & iSa_Num)
printf("1");
else
printf("0");
iSa_Temp2>>=1;
}
printf("\nExponential Part : ");
for(iSa_cnt=1;iSa_cnt<=iSa_incr;iSa_cnt++)
printf("%d",iSa_Array[iSa_cnt]);
while(iSa_incr<36)
{
iSa_temp=fSa_Frac*=2;
printf("%d",iSa_temp);
fSa_Frac-=iSa_temp;
iSa_incr++;
}
printf("\n\n");
}
// FUNCTION TO CONVERT INTEGER TO BINARY VALUE AND DISPLAY THE RESULT
int Sa_Convert(int iSa_Num,int iSa_Bits)
{
unsigned int iSa_TempNum=1<
{
if(iSa_TempNum & iSa_Num)
printf("1");
else
printf("0");
iSa_TempNum>>=1;
}
return 0;
}
--------------------------------------------output----------------------------------------------
1. Integer To 24-Bit Binary Convertion.
2. String To 8-Bit ASCII Value Convertion.
3. Negative Number To Binary Convertion
4. Fractional Number To 48-Bit Floating Point
1
Enter Your Integer Value : 32
Corresponding Binary Number is : 000000000000000000100000
1. Integer To 24-Bit Binary Convertion.
2. String To 8-Bit ASCII Value Convertion.
3. Negative Number To Binary Convertion
4. Fractional Number To 48-Bit Floating Point
2
Enter Your String : asdf
01100001 01110011 01100100 01100110
1. Integer To 24-Bit Binary Convertion.
2. String To 8-Bit ASCII Value Convertion.
3. Negative Number To Binary Convertion
4. Fractional Number To 48-Bit Floating Point
3
Enter Negative Integer Value : sad
invalid input
1. Integer To 24-Bit Binary Convertion.
2. String To 8-Bit ASCII Value Convertion.
3. Negative Number To Binary Convertion
4. Fractional Number To 48-Bit Floating Point
3
Enter Negative Integer Value : -3
Corresponding 2's Complement is : 11111111111111111111111111111101
1. Integer To 24-Bit Binary Convertion.
2. String To 8-Bit ASCII Value Convertion.
3. Negative Number To Binary Convertion
4. Fractional Number To 48-Bit Floating Point
4
Enter a Fractional Value : -4.5
Sign Bit : 1
Mantissa Part : 00010000001
Exponential Part : 001000000000000000000000000000000000
No comments:
Post a Comment