#include<stdio.h>
#include<stdlib.h>
void x(char *);
int f1(int,int);
int hex()
{
char a[10];
char* b;
printf("\nEnter the hexdecimal value : ");
scanf("%s",&a);
x(a);
return 0;
}
void x(char *a)
{
int sum=0,b;
int c=strlen(a);
b=c;
for (int i=0;i<c;i++)
{
if(a[i] >= '0' && a[i] <= '9')
{
sum = sum + f1(a[i]-'0',b);
b--;
}
else if(a[i] >= 'a' && a[i] <= 'f')
{
sum = sum + f1(a[i]-'a'+10,b);
b--;
}
else if(a[i] >= 'A' && a[i] <= 'F')
{
sum = sum + f1(a[i]-'A'+10,b);
b--;
}
else printf("Error value entered\n");
}
printf("\nResultant decimal value is : %d \n",sum);
}
int f1(int a, int b)
{
int d;
int p=1;
if(b != 0){
for (int i=1;i<b;i++)
p = p*16;
}
d=a*p;
return d;
}
void x(char *);
int f1(int,int);
int hex()
{
char a[10];
char* b;
printf("\nEnter the hexdecimal value : ");
scanf("%s",&a);
x(a);
return 0;
}
void x(char *a)
{
int sum=0,b;
int c=strlen(a);
b=c;
for (int i=0;i<c;i++)
{
if(a[i] >= '0' && a[i] <= '9')
{
sum = sum + f1(a[i]-'0',b);
b--;
}
else if(a[i] >= 'a' && a[i] <= 'f')
{
sum = sum + f1(a[i]-'a'+10,b);
b--;
}
else if(a[i] >= 'A' && a[i] <= 'F')
{
sum = sum + f1(a[i]-'A'+10,b);
b--;
}
else printf("Error value entered\n");
}
printf("\nResultant decimal value is : %d \n",sum);
}
int f1(int a, int b)
{
int d;
int p=1;
if(b != 0){
for (int i=1;i<b;i++)
p = p*16;
}
d=a*p;
return d;
}
No comments:
Post a Comment