@echo off :loop set/p string=input call:IsHex string if "%errorlevel%"=="0" (echo The string is hexadecimal.) if "%errorlevel%"=="1" (echo The string is not hexadecimal.) echo. call:IsInteger string if "%errorlevel%"=="0" (echo The string is decimal.) if "%errorlevel%"=="1" (echo The string is not decimal.) goto loop :IsInteger call:IsHex %1 10&&exit/b0||exit/b1 :IsHex setlocal set var=%% %1 %% set var=%var: =% call set var=%var% if "%2"=="10" (if "%var:~0,1%"=="-" (set var=%var:~1%)) else (if "%var:~0,2%"=="0x" (set var=%var:~2%)) set IsHex=0 set var=%var:0= % set var=%var:1= % set var=%var:2= % set var=%var:3= % set var=%var:4= % set var=%var:5= % set var=%var:6= % set var=%var:7= % set var=%var:8= % set var=%var:9= % if "%2"=="10" (goto ishex_) set var=%var:A= % set var=%var:B= % set var=%var:C= % set var=%var:D= % set var=%var:E= % set var=%var:F= % :ishex_ set var=%var: =% if defined var (set IsHex=1) endlocal&exit/b%IsHex%
Aug 31, 2013
Function: IsInteger
This lets your batch code check if input is decimal or hexadecimal. Other positional systems can be easily added if necessary. Supports signed numbers (decimal).
Labels:
batch_tip
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment