home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1995 November
/
PCWK1195.iso
/
inne
/
podstawy
/
dos
/
4dos
/
4uzytki
/
4dtnt.exe
/
STRING.ZIP
/
FROMDEC.BTM
< prev
next >
Wrap
Text File
|
1991-10-29
|
2KB
|
70 lines
if "%1" == "" .or. "%2" == "" .or. "%[%2]" == "" goto help
set $foo=%@upper[%1]
set $wstr=0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
gosub valdec
if %$val gt 9 (gosub cleanup ^ goto helpval)
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
set %2=%$foo ^gosub cleanup^quit 0
:cleanup
unset $foo $wstr $val $base >& nul
return
:base
set $base=%$foo
gosub cnvtit
return
:cnvtit
set $div=%$foo
set $num=%@upper[%[%2]]
set $temp=0
set $foo=
:cnvtloop
set $temp=%@eval[%$num %% %$base]
set $foo=%@substr[%$wstr,%$temp,1]%$foo
set $num=%@eval[%$num - %$temp]
set $num=%@eval[%$num / %$base]
if %$num gt 0 goto cnvtloop
:cnvtexit
unset $div $num $temp >& 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
:valdec
set $i=0
:valdoop
set $val=%@index[%$wstr,%@substr[%[%2],%$i,1]]
if %$val lt 0 .or. %$val gt 9 (set $val=99 ^ goto valdexit)
set $i=%@eval[%$i+1]
if %$i lt %@len[%$foo] goto valdoop
:valdexit
unset $i >& NUL
return