Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for num2bin.bat

(view source code of num2bin.bat as plain text)

  1. @ECHO OFF
  2. IF NOT "%OS%"=="Windows_NT" GOTO Syntax
  3. IF      "%~1"==""           GOTO Syntax
  4. IF NOT  "%~2"==""           GOTO Syntax
  5.  
  6. SETLOCAL ENABLEDELAYEDEXPANSION
  7. SET /A Num = %~1
  8. SET Bin=
  9.  
  10. :Loop
  11. SET /A "BinTmp = Num %% 2"
  12. SET /A Num /= 2
  13. SET Bin=%BinTmp%%Bin%
  14. IF %Num% GTR 0 GOTO Loop
  15.  
  16. ECHO.%Bin%
  17.  
  18. ENDLOCAL
  19. GOTO:EOF
  20.  
  21.  
  22. :Syntax
  23. ECHO.
  24. ECHO Num2Bin.bat,  Version 1.00 for Windows NT4 and later
  25. ECHO Convert the specified number to binary
  26. ECHO.
  27. ECHO Usage:  NUM2BIN  number
  28. ECHO.
  29. ECHO Where:  number   is a decimal, hexadecimal or octal number
  30. ECHO                  (0xnnn for hexadecimal, 0nnn for octal)
  31. ECHO.
  32. ECHO Note:   Non-numeric input will be treated as 0
  33. ECHO.
  34. ECHO Written by Rob van der Woude
  35. ECHO http://www.robvanderwoude.com
  36.  
  37. IF "%OS%"=="Windows_NT" EXIT /B 1
  38.  

page last modified: 2024-04-16; loaded in 0.0074 seconds