Qbasicnews.com

Full Version: Change numeric system
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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


Luis: It is not considered good form to post the same question  in more than one site at a time.  Several of us have already answered you in Pete's QuickBASIC Site.

Luis:  No está bien considerado el poner la misma pregunta en más de un sitio a la vez.  Ya varios le hemos contestado en Pete’s QuickBASIC Site.