Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Homework HelpRSS Feeds

PRORAM TO CONVERT HEXADECIMAL VALUE TO OCTAL USING FLOAT VALUES

Posted By: Reggie Fischer     Category: C Programming     Views: 5844

WRITE A PRORAM TO CONVERT HEXADECIMAL VALUE TO OCTAL USING FLOAT VALUES.

Code for PRORAM TO CONVERT HEXADECIMAL VALUE TO OCTAL USING FLOAT VALUES in C Programming

#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<math.h>
void main()
{
    int a[20],b[20],c[20],rev[20];
    int i,j,k,l,flag,cntint,cntfra,rem,num1,num3;
    char s[20];
    float rem1,num2,num4;
    clrscr();
    rem1=num2=num4=0.0;
    i=j=k=flag=cntint=cntfra=rem=num1=num3=0;
    printf("ENTER THE HEXADECIMAL VALUE : ");
    scanf("%s",s);
    for(i=0;i<strlen(s) ;i++)
    {
        if(s[i]=='.')
        {
            flag=1;
        }
        elseif(flag==0)
        {
            if(s[i]=='A')
            {
                a[j++]=10;
            }
            elseif(s[i]=='B')
            {
                a[j++]=11;
            }
            elseif(s[i]=='C')
            {
                a[j++]=12;
            }
            elseif(s[i]=='D')
            {
                a[j++]=13;
            }
            elseif(s[i]=='E')
            {
                a[j++]=14;
            }
            elseif(s[i]=='F')
            {
                a[j++]=15;
            }
            else
            {
                a[j++]=s[i]-48;
            }
        }
        elseif(flag==1)
        {
            if(s[i]=='A')
            {
                b[k++]=10;
            }
            elseif(s[i]=='B')
            {
                b[k++]=11;
            }
            elseif(s[i]=='C')
            {
                b[k++]=12;
            }
            elseif(s[i]=='D')
            {
                b[k++]=13;
            }
            elseif(s[i]=='E')
            {
                b[k++]=14;
            }
            elseif(s[i]=='F')
            {
                b[k++]=15;
            }
            else
            {
                b[k++]=s[i]-48;
            }
        }
    }
    cntint = j;
    cntfra = k;
    for(j=0,i=cntint-1;i>=0;i--,j++)
    {
        rem = rem + (a[j] * pow(16,i));
    }
    for(j=0,i=1;j<cntfra;j++,i++)
    {
        rem1 = rem1 + (b[j] / pow(16,i));
    }
    rem1 = rem1 + rem;
    num1 = (int)rem1;
    num2 = rem1 -num1;
    i=0;
    rem = 0;
    while(num1!=0)
    {
        rem = num1 % 2;
        rev[i] = rem;
        num1 = num1 / 2;
        i++;
    }
    j=0;
    while(num2!=0.0)
    {
        num2 =num2 * 2;
        num3 = (int) num2;
        num4 = num2 - num3;
        num2 = num4;
        a[j] = num3;
        j++;
        if(j==4)
        {
            break;
        }
    }
    l=i;
    printf ("\nTHE OCTAL VALUE OF GIVEN HEXADECIMAL VALUE IS : ");
    for(i=l-1;i>=0;i--)
    {
        printf("%d",rev[i]);
    }
    printf(".");
    for(k=0;k<j;k++)
    {
        printf("%d",a[k]);
    }
    getch();
}
/* OUTPUT
--------------------------------------------------------------------
ENTER THE HEXADECIMAL VALUE : 45.43

THE OCTAL VALUE OF GIVEN HEXADECIMAL VALUE IS : 1000101.0100
*/
  
Share: 



Reggie Fischer
Reggie Fischer author of PRORAM TO CONVERT HEXADECIMAL VALUE TO OCTAL USING FLOAT VALUES is from Frankfurt, Germany.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!