Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

A better @convert

samintz

Scott Mintz
May
1,587
27
The built-in @convert limits values to 64 bits. However, @eval can go up to 10000 digits. I wrote the following script as an alternative.

Code:
setlocal
if %1 == %2 (echo %3 & quit)
if %1 == 10 (call :BaseX %3 %2 & quit)
if %2 == 10 (call :Base10 %3 %1 & quit)
Call :BaseX %@execstr[call :Base10 %3 %1] %2
quit

:BaseX 
set b10=%1
set result=
do until %b10==0
    set rmndr=%@eval[((%b10 / %2) - %@INT[%b10 / %2]) * %2]
    if %rmndr GT 9 set rmndr=%@char[%@eval[%rmndr + 55]]
    set result=%[rmndr]%[result]
    set b10=%@int[%b10 / %2]
enddo
if %result.==. set result=0
echo %result
quit

:Base10
set b2=%1
set result=0
do until %b2.==.
    set digit=%@left[1,%b2]
    iff %@ascii[%digit] GT 57 then 
        set digit=%@eval[(%@ascii[%digit] OR 32) - 87]
    endiff
    set result=%@eval[(%result * %2) + %digit]
    set b2=%@right[-1,%b2]
enddo
echo %result
quit

endlocal

Here is the function:
Code:
function cvt=`%@execstr[convert.btm %1 %2 %3]`

And here are some examples:
Code:
echo %@cvt[10,12,%@eval[13000 * 33333 * 31416 * 27813 * 98765 * 43210]]
183AB5A45118A2082453522000
echo %@cvt[12,10,183AB5A45118A2082453522000]
1615860307974787525450800000

-Scott
 
Back
Top