|
Post by honkytonk on Jun 16, 2019 9:12:28 GMT
Hello all, I am looking for a code in Just / Liberty Basic to convert from decimal to hexadecimal. Thank you in advance.
|
|
|
Post by B+ on Jun 16, 2019 11:11:25 GMT
Built in DECHEX$ and HEXDEC$ (v 2.0)
do input "Enter number to convert to hexadecimal ";dec print dechex$(dec) print loop until dec = 0
|
|
|
Post by honkytonk on Jun 16, 2019 13:46:42 GMT
Built in DECHEX$ and HEXDEC$ (v 2.0) do input "Enter number to convert to hexadecimal ";dec print dechex$(dec) print loop until dec = 0
I should want a code (algo) for the V1
EDIT: It's good, I took the V2, but it's not worth a good algo in which we see what happens.
|
|
|
Post by B+ on Jun 16, 2019 15:57:19 GMT
I don't now how good it is but here is generic converter for Positive Integers and small bases:
while 1 Input "Enter base for converting numbers (0 quits) ";b if b = 0 then end do Input "Enter number to convert (0 quits converting for next base)";n print Dec2Base$(n, b) print loop until n = 0 wend function Dec2Base$(nDec, base) p = 0 while base ^ p <= nDec scan p = p + 1 wend 'print "p=";p for pow = p to 0 step -1 scan if nDec >= base ^ pow then d = int(nDec / base ^ pow) 'print "d=";d if d < 10 then b$ = b$ + str$(d) else b$ = b$ + chr$(65 + d - 10) end if nDec = nDec - d * base ^ pow else if b$ <> "" then b$ = b$ + "0" end if next if b$ = "" then b$ = "0" Dec2Base$ = b$ end function
|
|
|
Post by honkytonk on Jun 16, 2019 16:16:01 GMT
Wonderful! Thank you véry much B + The goal is to copy paste from an RGB table in the converter, then copy paste from the converter into a html page; with texteditor et word$
|
|