CONVBASE$ CONVERSION Function Windows/Unix


A conversion function which takes the string expression represented in a specified base to be converted to another specified base determined by the arguments passed.

Syntax: CONVBASE$(string-expression, frombase, tobase)
S$ = CONVBASE$("FFD", 16, 2) '-- Convert from base 16 to 2
S$ = CONVBASE$("287", 10, 16) '-- Convert from base 10 to 16

Details:
Use the Snakedile LIBs dated Nov. 2006 or later. CONVBASE$ is made case-insensitive and accurate to 63 bits positive, 32 bits negative. It will also accept base signifiers in input string
e.g...
CONVBASE$("&HFFffFFff" , 16, 10) or
CONVBASE$("ffffFFFFh", 16, 10) will produce exactly the same results as CONVBASE$("FFFFFFFF", 16, 10).

If you use  Negative numbers then consider this code:

'/* Start of Code */
DefLng NUM = -2147483648 'NO Fractions! (RANGE: -2147483648 to 2147483647)
DefDbl DBL = 0 'Has To Be DOUBLE
DefStr PAD = "00000000000000000000000000000000"
DefStr BIN = Right$(PAD & Bin$(NUM), 32)
DefStr STR = ""

'Replace RichEdit.AddString with Print (if that's your preference)

RichEdit.AddString("--------------------------------")
RichEdit.AddString(BIN)
RichEdit.AddString("-----------")
DBL = Val(ConvBase$(BIN, 2, 10))
STR = IIf((DBL > 2147483647), Strf$((DBL - 4294967296), ffGeneral, 10, 0), Strf$(DBL, ffGeneral, 10, 0))
RichEdit.AddString(STR)
'/* End of Code */