Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Change numeric system
#1
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


Reply
#2
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.

Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
Reply
#3
The program is correct:

http://www.petesqbsite.com/forum/viewtopic.php?t=2746

Thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)