JavaScript - Numeros decimal a hexadecimal

 
Vista:

Numeros decimal a hexadecimal

Publicado por Juck (3 intervenciones) el 04/02/2003 16:14:52
Saludos y gracias de antemano.

Necesito saber si se puede convertir un número en base 10 (decimal) a su base 16 (Hexadecimal) con javascript, ya lo hago con ASP, pero quiero evitar el envío de la forma para el cálculo.

Juck.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:ya lo encontre gracias, por si alguien lo neces

Publicado por Cristian Goncalves (3 intervenciones) el 07/02/2003 18:07:05
<form>
<input type=\"text\" name=\"dec\" onBlur=\"hex.value=(this.value-0).toString(16)\">(dec)
<input type=\"text\" name=\"hex\" onBlur=\"dec.value=parseInt(this.value,16)\">(hex)
</form>

To convert the hexadecimal, I just use the parseInt function with the additional parameter \'16\'. To convert from decimal to hexadecimal, I use the toString method, with parameter \'16\'. But since the value in the \'decimal\' field is already a String object, it first needs to be casted to an Int. I do this by subtracting zero (0). It then is a number and it can be converted to a String, base 16.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar