> >?basex(249272136572 , "0123456789abcdef") >?basex(-77442022681, "0123456789abcdef") > >Function BaseX( txVal, tcDom ) > * Converts a number to a string representation of that number > * tnVal - Number > * tcDom - The domain of characters to be used > * typical Domains are: > * "01" - Binary > * "0123456789" - Decimal > * "0123456789abcdef" - Hex > * "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" - Base62 > * "23456789ABCDEFGHJKLMNPRSTUVWXYZ" - No {01IOQ} - they might confuse a user. > > * If you want the result padded, use PADL() > > Local ; > lnVal, ; > lnDomSiz, ; > lcRet, ; > lnPosition, ; > lnPlace > > If Vartype(txVal) = "N" > If txVal < 0 Then > txVal = txVal + 1 > Endif > lnVal = txVal > lnDomSiz = Len(tcDom) > > * Humans get restless if the value zero is displayed as an empty string (blank). > * The first char of the domain (generally 0) is normally used as a place holder, > * but in the case of the value zero, it fills in to keep the peace. > * This may have lead to the fall of Rome. > > If lnVal = 0 > lcRet = Substr( tcDom, 1, 1 ) > Else > lcRet = '' > Do While lnVal <> 0 > lnDig = lnVal % lnDomSiz > lnVal = Int( lnVal/lnDomSiz ) > If txVal > 0 Then > lcDig = Substr( tcDom, lnDig+1, 1 ) > Else > If lnDig = 0 Then > lnDig = 16 > Endif > lcDig = Substr( tcDom, lnDig, 1 ) > Endif > > lcRet = lcDig + lcRet > Enddo > Endif > lxRet=lcRet > Else > * Convert it back to decimal > lnVal = 0 > lnPlace = 0 > For lnPosition = Len(txVal) To 1 Step -1 > lnVal = lnVal + (At( Substr(txVal,lnPosition,1), tcDom)-1) * (Len(tcDom)^lnPlace) > lnPlace=lnPlace+1 > Endfor > lxRet = lnVal > Endif > > Return lxRet >Endfunc >>