home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1995 November
/
PCWK1195.iso
/
inne
/
podstawy
/
dos
/
4dos
/
4uzytki
/
4dtnt.exe
/
STRING.ZIP
/
TODEC.DOC
< prev
next >
Wrap
Text File
|
1991-10-29
|
2KB
|
63 lines
if "%1" == "" .or. "%2" == "" .or. "%[%2]" == "" goto help
set $foo=%@upper[%1]
set $wstr=0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
iff %$foo = B then ^ set $foo=2
elseiff %$foo = O then ^ set $foo=8
elseiff %$foo = H then ^ set $foo=16
elseiff %$foo = D then ^ set $foo=10
endiff
iff %$foo gt 1 .and. %$foo lt 37 then ^ gosub base
else goto help
endiff
iff %$val ne 0 then^unset %2 ^ (gosub cleanup^goto helpval)
else set %2=%$foo ^gosub cleanup^quit 0
endiff
quit
:cleanup
unset $foo $wstr $val $max >& nul
return
:base
set $max=%$foo
gosub cnvtit
return
:cnvtit
set $foo=%@upper[%[%2]]
set $i=%@eval[%@len[%$foo]-1]
set $mult=1
set $accum=0
:cnvtloop
set $val=%@index[%$wstr,%@substr[%[%2],%$i,1]]
if %$val lt 0 .or. %$val ge %$max (set $val=%$max^goto cnvtexit)
set $accum=%@eval[%$accum+%@eval[%$val*%$mult]]
set $mult=%@eval[%$mult*%$max]
set $i=%@eval[%$i-1]
if %$i ge 0 goto cnvtloop
set $foo=%$accum
set $val=0
:cnvtexit
unset $i $mult $accum >& nul
return
:helpval
echo Invalid character detected.
echo .
goto help
:help
echo Usage: %@name[%0] mode var
echo.
echo var = Any environment variable whose value is the input
echo mode = any of:
echo B=binary [0-1]
echo D=decimal [0-9]
echo H=hex [0-F]
echo O=octal [0-7]
echo [2-36] [0-(n-1)]
echo New value returned in var, replacing original value
quit 4