
24/09/2004, 09:15
|
| | Fecha de Ingreso: abril-2004 Ubicación: México D.F.
Mensajes: 1.724
Antigüedad: 21 años Puntos: 4 | |
Viendo mis apuntes pruebate este, te convierte de binario a decimal con validaciones.
Adpatalo a tus necesidades.
<script language="vbscript">
'alumno Orlando Rios
' materia Ensamblador
' fecha : 13-02-2002
option explicit
function convierte()
dim contador,digito,exponente,acomulador
acomulador=0
exponente=1
contador=len(binario.value)
if(contador=0) then
alert("Ingrese un valor binario")
exit function
end if
while(contador>=1)
digito=mid(binario.value,contador,1)
if(not(isnumeric(digito)))then
msgbox "La expresión [" & binario.value & "] no es válida ---> " & digito & " <---"&chr(13)&"No ingrese letras ní caracteres especiales."&chr(13)&"Ingrese únicamente valores numericos (0 y 1)",16+vbsystemmodal,"Error"
binario.select
exit function
end if
if(digito<>1 and digito<>0)then
msgbox "La expresión ( " & binario.value & " ) no es válida ---> " & digito & " <---"&chr(13)&"Ingrese únicamente valores binarios (0 y 1)",16+vbsystemmodal,"Error"
binario.select
exit function
end if
if(digito=1)then
acomulador=acomulador+exponente
end if
exponente=exponente*2
contador=contador-1
wend
msgbox "La conversión de " & binario.value & " a decimal es : <<" & acomulador&" >>",vbinformation,""
end function
function hola(texto)
msgbox texto
end function
</script><input name="binario"><input type="button" value="Convertir Binario a Decimal" onclick="convierte()"> |