Besoin d'aide en java
mancinij
-
mancinij -
mancinij -
salut tout le monde ,
j'aimerai bien connaitre l'agorithme qui me permet de convertir un hexadecimal en decimal dans Java. Comment mon algorithme devant un A oud saura convertir?
merci pour ton aide .
j'aimerai bien connaitre l'agorithme qui me permet de convertir un hexadecimal en decimal dans Java. Comment mon algorithme devant un A oud saura convertir?
merci pour ton aide .
2 réponses
-
voila une fonction pour le faire
public int hexConversion(String y)
{
int res = 0;
for (int i = 0; i < y.length(); i++)
{
res *= 16;
int v = ((int) y.charAt(i));
if (v >= 48 && v < 58) v -= 48;
else if (v >= 65 && v < 71) v -= 55;
else if (v >= 97 && v < 103) v -= 87;
else throw new
NumberFormatException("Expected decimal or hexadecimal number");
res += v;
}
return res;
} -