# Thread: From It DEcimal them to esadecimale

1. ## From It DEcimal them to esadecimale

you know an algorithm that converts numbers DEcimal them in esadecimali?

2. I guess esadecimali is Italian for hexadecimal? Hexadecimal and decimal are number representations, they represent the same number but use another base. So there is no need for conversion.

Can you give an example of what you want? To help you better we need an example of input and output to see what you want to do.

3. this is my stupid programm Crypt
this program in output is print a decimal number

Code:
```/*
Name: CRYPT
Author: KRAKZ
Date: 12/02/03 14.39
Description: CRITTOGRAFIA
LICENZA : GNU|GPL
VERSIONE : 0.2
*/

# include <stdio.h>
# include <string.h>
#include <stdlib.h>
# define MAX 255

int main (void)
{
int i, I = 0 , countchiave , countfrase , crypt[MAX] , crypt2[MAX] ,crypt1[MAX] ;
char frase[MAX] , frase1[MAX], chiave[MAX] ;

printf ("Inserisci frase\n") ;
gets(frase) ;
printf ("Inserisci chiave\n") ;
gets(chiave) ;

countfrase  = strlen(frase)  ;
countchiave = strlen(chiave) ;

;
for ( i = 0 ; countfrase > i ; i++)
{

if ( countchiave < I)
I = 0 ;;
crypt1[i] = chiave [I] ;
crypt2[i] = frase[i]  ;
crypt[i] =  crypt1[i] + crypt2[i] ;
if ( crypt[i] < 100 )
printf ("0") ;;
printf ("%d" , crypt[i]) ;
I = 1 + I ;
}
printf ("\n") ;
system("PAUSE");

}

this  is a Decrypt

is riceved the number of crypt and key and decrypt```
Code:
```/*
Name: dECRYPT
Author: KRAKZ
Date: 12/02/03 14.39
Description: DeCRPTA
LICENZA : GNU|GPL
VERSIONE : 0.2
*/

# include <stdio.h>
# include <string.h>
#include <stdlib.h>
# define MAX 255

int main (void)
{ int I=0 , i , countfrase , countchiave , dEcrypt[MAX] , de = 0 ;
char frase[MAX] , chiave[MAX] ;

printf ("Inserisci File Cryptato\n") ;
gets(frase) ;
printf ("Inserisci chiave\n") ;
gets(chiave) ;

countfrase = strlen(frase) ;
countchiave = strlen(chiave) ;

for ( i = 0 ; countfrase > i ; i = 3 + i)
{ ;
if ( countchiave < I)
I = 0 ;;

dEcrypt[de] = (frase[i]* 100 + frase [i+1] * 10 + frase [i+2] +48 ) - chiave [I] ;
printf ("%c" , dEcrypt[de]) ;
I = 1 + I ;
de = de + 1 ;

}
printf ("\n") ;

system("PAUSE");

}```
for optimizer mi code , i mind use of Hexadecimal in substitution to it decimal them

P.S : My English is terrible ;( ;( ;(

4. help me

5. - Don't use gets()
- Don't bump your threads
- What exactly is your question again?

>>My English is terrible
Your're not kidding Try explaining by using a simple example of what you want to do.

6. #include <stdio.h>

main ()
{

int decimal , Hexadecimal ;
printf ("Enter Hexadecimal number :\n") ;
scanf ("%d" , Hexadecimal) ;

/* in this point algorithm of conversation of number */
/*................................................. .*/

printf ("%d" , decimal ) ;

}

7. Okay, I understand now, I think. You have an integer number as input, like 123. This is not 123 in decimal, but 123 in hexadecimal right? So in decimal it is 291.

In that case, realise that the base of the hexadecimal system is 16. To convert it to decimal you need to apply this conversion:

1 * 16^2 + 2 * 16^1 + 3 * 16^0 = 291

So in general when you have a hexadecimal value:

h[n] h[n-1] ... h[2] h[1] h[0]

You need to perform the conversion:

h[n] * 16^[n] + h[n-1] * 16^[n-1] + ... + h[1] * 16^1 + h[0] * 16^0

Hope this helps.

8. Originally posted by Shiro
Okay, I understand now, I think. You have an integer number as input, like 123. This is not 123 in decimal, but 123 in hexadecimal right? So in decimal it is 291.

In that case, realise that the base of the hexadecimal system is 16. To convert it to decimal you need to apply this conversion:

1 * 16^2 + 2 * 16^1 + 3 * 16^0 = 291

So in general when you have a hexadecimal value:

h[n] h[n-1] ... h[2] h[1] h[0]

You need to perform the conversion:

h[n] * 16^[n] + h[n-1] * 16^[n-1] + ... + h[1] * 16^1 + h[0] * 16^0

Hope this helps.

scuse me

but I have

Example : FE1 (HEXADECIMAL) = 4065 (DECIMAL)

F * 16^2 + E* 16^1 + 1 * 16^0 = 4065

what algorithm for convert "F" (HEXADECIMAL) in 15.

15 * 16^2 + 14 * 16^1 + 1 * 16 ^ 0 = 4065.

P.S: Scuse me for my bad english and for my stupid questions

9. Here's one way:
Code:
```#include <stdio.h>

int main(void)
{
long int num;

printf ("Enter a hex number: ");
if (scanf("%x", &num) == 1)
printf ("Thats %ld in decimal\n", num);

return 0;
}```

10. You were using %d, which confused me, because then you cannot enter an input like FE1. You can do that if you use %x, like Hammer showed. To store it in a variable, you could also consider using the function sprintf().

#include <stdio.h>
int sprintf (char * restrict s, const char * restrict format, ...);

Popular pages Recent additions