Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for dectobin.bat

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

  1. @ECHO OFF
  2. SETLOCAL
  3. SET /A Decimal = %1 +0 >NUL 2>&1 || GOTO Syntax
  4. IF %Decimal% LSS 0 GOTO Syntax
  5.  
  6. SET Binary=
  7. SET Scratch=%Decimal%
  8.  
  9. :Loop
  10. SET /A "LSB = %Scratch% %% 2"
  11. SET /A "Scratch = %Scratch% >> 1"
  12. SET Binary=%LSB%%Binary%
  13. IF NOT %Scratch% EQU 0 GOTO Loop
  14.  
  15. SET Decimal
  16. SET Binary
  17.  
  18. ENDLOCAL
  19. EXIT /B
  20.  
  21.  
  22. :Syntax
  23. ECHO.
  24. ECHO DecToBin.bat,  Version 1.00
  25. ECHO Convert a decimal number to 31-bit binary
  26. ECHO.
  27. ECHO Usage:  DECTOBIN  number
  28. ECHO.
  29. ECHO Where:  number    is a 32-bit positive integer or calculation
  30. ECHO                   (0..2,147,483,647 or 0..017777777777)
  31. ECHO.
  32. ECHO Notes:  This batch file uses CMD.EXE's internal commands only.
  33. ECHO         Return code ("ErrorLevel") 0 if conversion was successful,
  34. ECHO         otherwise 1.
  35. ECHO.
  36. ECHO Written by Rob van der Woude
  37. ECHO https://www.robvanderwoude.com
  38. ENDLOCAL
  39. EXIT /B 1
  40.  

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