08-19-2008, 12:51 AM
Hello everyone:
Someone can tell me that this program works well sometimes and other sometimes bad?
Example 1: Decimal >> Binary
Example 2: Base 6Â >> Base 25
Example 3: Base 10 >> Base 4
'Este programa transforma un numero entre sistemas numericos distintos
'Peligro, no funciona bien siempre, sobre todo con base 2. ???
CLS
INPUT "Number to transform : "; numorg
INPUT "Base init : "; basorg
INPUT "Base end "; basdes
'Aqui transformamos el numero a base 10
a$ = LTRIM$(STR$(numorg))
c = LEN(a$)
FOR d = c - 1 TO 1 STEP -1
e$ = MID$(a$, d, 1)
x# = x# + (VAL(e$) * (basorg ^ (c - d)))
NEXT d
e$ = MID$(a$, c, 1)
x# = x# + (VAL(e$) * 1)
a# = x#
d = 0
'De base 10 lo transformamos a la base destino
DO
c# = a# / basdes
d# = a# MOD basdes
a1$ = a1$ + LTRIM$(STR$(d#))
IF c# <> 1 THEN a# = INT(c#)
LOOP UNTIL a# <= basdes
a1$ = a1$ + LTRIM$(STR$(INT(c#)))
g = LEN(a1$)
FOR f = g TO 1 STEP -1
c$ = MID$(a1$, f, 1)
b$ = b$ + c$
NEXT f
PRINT b$
END
Someone can tell me that this program works well sometimes and other sometimes bad?
Example 1: Decimal >> Binary
Example 2: Base 6Â >> Base 25
Example 3: Base 10 >> Base 4
'Este programa transforma un numero entre sistemas numericos distintos
'Peligro, no funciona bien siempre, sobre todo con base 2. ???
CLS
INPUT "Number to transform : "; numorg
INPUT "Base init : "; basorg
INPUT "Base end "; basdes
'Aqui transformamos el numero a base 10
a$ = LTRIM$(STR$(numorg))
c = LEN(a$)
FOR d = c - 1 TO 1 STEP -1
e$ = MID$(a$, d, 1)
x# = x# + (VAL(e$) * (basorg ^ (c - d)))
NEXT d
e$ = MID$(a$, c, 1)
x# = x# + (VAL(e$) * 1)
a# = x#
d = 0
'De base 10 lo transformamos a la base destino
DO
c# = a# / basdes
d# = a# MOD basdes
a1$ = a1$ + LTRIM$(STR$(d#))
IF c# <> 1 THEN a# = INT(c#)
LOOP UNTIL a# <= basdes
a1$ = a1$ + LTRIM$(STR$(INT(c#)))
g = LEN(a1$)
FOR f = g TO 1 STEP -1
c$ = MID$(a1$, f, 1)
b$ = b$ + c$
NEXT f
PRINT b$
END