0% found this document useful (0 votes)
10 views3 pages

Convertidor de Hex

The document contains C code for converting a hexadecimal number to its decimal equivalent. It includes functions for conversion and input handling, but has several syntax errors and logical issues. The code attempts to read a hexadecimal number, process it, and output the decimal result, but fails due to incorrect variable handling and control structures.

Uploaded by

Jhosep Nuñez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views3 pages

Convertidor de Hex

The document contains C code for converting a hexadecimal number to its decimal equivalent. It includes functions for conversion and input handling, but has several syntax errors and logical issues. The code attempts to read a hexadecimal number, process it, and output the decimal result, but fails due to incorrect variable handling and control structures.

Uploaded by

Jhosep Nuñez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

#include <stdio.

h>
#include <string.h>
#include <stdin.h>

int convtodec(char * a);


int converting (char * a);

int main(void) {
char * i;
printf("Número hex: ");
scanf("%c", &i);

char * hexnumber = i;

int result = convtodec(hexnumber);

printf("0x%c es igual a %i en decimal. \n", hexnumber, result);


}

int convtodec(char * a)
{
int length = strlen(a);
int check = length % 2;

if (check = 0)
{
int pos = length - 1;

int div = length / 2;

char * pairs[div];

int decnumbers[length];

int result;

for (int i = 1; i <= div, i++);


{
char * q = a[pos];
char * r = a[pos - 1];

char * w = r + q;

pairs[i - 1] = w;

pos = pos - 2;
}

for (int i = 1, i <= length, i++);


{
int converted = converting(pairs[i - 1]);

decnumbers[i - 1] = converted;
}

int x = decnumbers[i - 1] * (16 ^ (i - 1) );

int y;
int z = 0;

for (i = 1, i <= 7, i++)


{
y = decnumbers[i] * (16 ^ i );

z += y;
}

result = x + z;

return result;
}

else
printf("Número hexadecimal incompleto.\n");
return 1
}
}

int converting (char * a)


{
if (a = "0")
{
int y = 0
}
else if (a = "1")
{
int y = 1;
}
else if (a = "2")
{
int y = 2;
}
else if (a = "3")
{
int y = 3;
}
else if (a = "4")
{
int y = 4
}
else if (a = "5")
{
int y = 5;
}
else if (a = "6")
{
int y = 6;
}
else if (a = "7")
{
int y = 7;
}
else if (a = "8")
{
int y = 8;
}
else if (a = "9")
{
int y = 9;
}
else if (a = "A" || "a")
{
int y = 10;
}
else if (a = "B" || "b")
{
int y = 11;
}
else if (a = "C" || "c")
{
int y = 12;
}
else if (a = "D" || "d")
{
int y = 13;
}
else if (a = "E" || "e")
{
int y = 14;
}
else if (a = "F" || "f")
{
int y = 15;
}
else
{
return 1;
}

return y
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy