Código:
@echo off
::D2B
::Por: The Shadow|Shadow
::Info: Convierte un numero decimal a binario
::Parametros: %1=numero decimal
::Devuelve: %bin%=numero binario
::Nivel de precision:1 byte
:d2b
setlocal
if %1'==' goto err
set /a cmp=%1*1
if not %cmp%==%1 goto err
if /I %1 gtr 198 goto err
set bin=
set ay=%1
if %ay%==1 (set bin=1 && goto enda)
:aval
set lim=a
call :len %ay%
set /a lon=%len%-1
set lim=9
for /L %%a in (1,1,%lon%) do (
set lim=9%lim%
)
set lim=%lim: =%
set naa=0
:cnta
if "%naa%"=="%lim%" (goto tst)
set /a cy=%naa%*2
if /I "%cy%" EQU "%ay%" (
set bin=%bin%0
goto cmp
)
set /a naa=%naa%+1
goto cnta
:tst
set bin=%bin%1
:cmp
if /I %ay% lss 2 goto end
set /A ay=%ay%/2
goto aval
:ohce
set wrd=
set ohce=
if %1'==' goto er_o
set wrd=%1
set wrd=%wrd:"=cnf%
call :len %wrd%
set /a len=%len%-1
for /l %%a in (%len%,-1,0) do (
call :st %%wrd:~%%a,1%%
)
set ohce=%ohce:"=%
set ohce=%ohce:fnc="%
goto :EOF
:st
set p1=%1
set ohce=%ohce%%p1%
goto :EOF
:len
if %1'==' echo La sintaxis es: len [cadena] && goto :EOF
set w=%1
set a=0
set bol=0
:lp
call :cnt "%%w:~%a%,1%%" %a%
if %bol%==1 goto :EOF
set /a a=%a%+1
goto lp
:cnt
set cur=%1
set len=%2
if %cur%a==""a (
set bol=1
)
goto :EOF
:er_o
echo La sintaxis es: h2d [cadena]
goto :EOF
:err
echo La sintaxis es: && echo.
echo d2b [numero]
echo. && echo Los numeros estan limitados a 1 byte aprox.
goto :EOF
:end
call :ohce %bin%
set bin=%ohce%
:enda
echo %bin%
endlocal
goto :EOF