Okay, here is my final bisection thing, but it's now written
in only ONE Line.
That line is very long, exact 418 visible char long:
(if not defined Result ... goto%0
Two things are required: ".BAT" extension, and a variable
named Result must be empty.
The testing loop, in (2147483647, -33554428, 0),
would count down from 2147483647, and stop on 255.
If a loop with that same speed for each number you see, it would
have calc/found that number after more than four years. In other
words: if you run the test loop (take about 4 seconds), and then
see a message: 255. "All Done", Press any key ..., then you have
displayed the same data as would have taken more than 260 years,
So, I would say this loop is fast. Besides that, it shouldn't be
a problem for you to rewrite it for whatever, other purpose than
exit-codes/errorlevels...
Benny
@echo off
setlocal enabledelayedexpansion
(set Result=)
for /L %%I in (2147483647, -33554428, 0) do (
call :ErrMake %%I
call :ErrFind > nul
echo !ErrFind!.
REM if "!ErrFind!" neq "%%I" echo OOPS.& exit /b
)
endlocal
call:_& echo All Done.& pause
goto:eof
:ErrFind
(if "!Result!"=="" set Result=%0&set Result=!Result:~1!&(if not errorlevel 1 set !Result!=0&set Result=&goto:eof)&set H=2147483647&(if errorlevel !H! set !Result!=!H!&set Result=&goto:eof)&set L=0)&set/a A=H/2+L/2&echo H:!H! A:!A! L:!L!&(if errorlevel !A! ((if !L!==!A! set/a A+=1&(if not errorlevel !A! set A=!L!)&set !Result!=!A!&set Result=&goto:eof)&set L=!A!)else set H=!A!)&goto%0
:ErrMake X [norm/both/user]
if /i "%~2"=="norm" (set errorlevel=)
if /i "%~2"=="both" (set errorlevel=%~1)
if /i "%~2"=="user" (
cd.\&(set errorlevel=& if errorlevel 1 exit /b %~1
call:_
echo It is recognizable that a variable errorlevel
echo have been manipulated, value is %errorlevel%.
echo.
echo "%~nx0" is ready to create the exit-code %~1,
echo Please make a choice, 1...3:
echo.
echo 1: As requested, create an ERRORLEVEL %~1
echo.
echo 2: Also set the synthetic errorlevel variable
echo.
echo 3: Normalize/restore the synthetic errorlevel
echo so it is following the real DOS ERRORLEVEL
echo.& (set /p errorlevel=?: )
if "!errorlevel!"=="3" set errorlevel=&exit /b %~1
if "!errorlevel!"=="2" (set errorlevel=%~1) else (
set errorlevel=%errorlevel%))
)
exit /b %~1
:_
for %%_ in (________________) do (echo %%_%%_%%_%%_%%_) |
|