Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for dectooct.bat

(view source code of dectooct.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 Octal=
  7. SET Scratch=%Decimal%
  8.  
  9. :Loop
  10. SET /A LSB = %Scratch% %% 8
  11. SET /A "Scratch = %Scratch% >> 3"
  12. SET Octal=%LSB%%Octal%
  13. IF NOT %Scratch% EQU 0 GOTO Loop
  14.  
  15. SET Octal=0%Octal%
  16.  
  17. SET Decimal
  18. SET Octal
  19.  
  20. SET RC=0
  21. IF NOT %Decimal% EQU %Octal% (
  22. 	ECHO An error occurred, %Octal% is not equal to %Decimal%
  23. 	SET RC=1
  24. )
  25. ENDLOCAL & EXIT /B %RC%
  26.  
  27.  
  28. :Syntax
  29. ECHO.
  30. ECHO DecToOct.bat,  Version 1.01
  31. ECHO Convert a decimal number to "10.5" digit octal
  32. ECHO.
  33. ECHO Usage:  DECTOOCT  number
  34. ECHO.
  35. ECHO Where:  number    is a 32-bit positive integer or calculation
  36. ECHO                   (0..2,147,483,647 or 0..017777777777)
  37. ECHO.
  38. ECHO Notes:  This batch file uses CMD.EXE's internal commands only.
  39. ECHO         Return code ("ErrorLevel") 0 if conversion was successful,
  40. ECHO         otherwise 1.
  41. ECHO.
  42. ECHO Written by Rob van der Woude
  43. ECHO https://www.robvanderwoude.com
  44. ENDLOCAL
  45. EXIT /B 1
  46.  

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