Un convertisseur Decimal->Hexa "a l'envers"

Un convertisseur Decimal->Hexa "a l'envers" - C++ - Programmation

Marsh Posté le 21-04-2007 à 17:33:50    

Mon probleme est simple : je veut à partir d'un nombre décimal trouver l'hexa qui a la meme "valeur", en fait pas vraiment
 
Ex : j'ai 10 en décimal. Je cherche a trouver 10 en hexa...
J'ai écris un algo (divisions successives par 10) mais c'est tres lent : j'ai de tresgros nombres a transformer, de l'ordre de 1 million.. et les divisionspar 10 c'st lent sur ma plateforme.
 
Je ne sais pas si c'est bien clair, mais comment exprimer un nombre en décimal comme étant en hexa ? Je ne cherche as une conversion, ca c'est facile, mais plutot a exprimer un nombre décimal comme étant en hexa... 10 dec = 0x10 (meme si mathématiquement c'est faux  :D )
 
Une idée super rapide a exécuter ?


---------------
Un blog qu'il est bien
Reply

Marsh Posté le 21-04-2007 à 17:33:50   

Reply

Marsh Posté le 21-04-2007 à 17:53:37    

"0x%d"?


---------------
I mean, true, a cancer will probably destroy its host organism. But what about the cells whose mutations allow them to think outside the box, and replicate and expand beyond their wildest dreams by throwing away the limits imposed by overbearing genetic r
Reply

Marsh Posté le 21-04-2007 à 17:59:58    

Je pense qu'il veut un nombre en sortie. En gros, la formule mathematique qui, pour y donne, permet de trouver quel est le nombre x qui en hexa possede la meme ecriture que y en decimal. J'ai bon?

Reply

Marsh Posté le 21-04-2007 à 18:21:29    

Code :
  1. char[50] temp;
  2. sprintf(temp, "0x%d", 10);
  3. int hexValue = strtol(temp, NULL, 0);


?

Message cité 1 fois
Message édité par masklinn le 21-04-2007 à 18:22:13

---------------
I mean, true, a cancer will probably destroy its host organism. But what about the cells whose mutations allow them to think outside the box, and replicate and expand beyond their wildest dreams by throwing away the limits imposed by overbearing genetic r
Reply

Marsh Posté le 21-04-2007 à 18:53:35    

masklinn a écrit :

Code :
  1. char[50] temp;
  2. sprintf(temp, "0x%d", 10);
  3. int hexValue = strtol(temp, NULL, 0);


?


Merci !!  :bounce:  
Ca marche impeccable... pfff en plus en C c'est parfait  [:al_bundy]  
 
Bonne journée !


---------------
Un blog qu'il est bien
Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed