Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for num2hex.bat

(view source code of num2hex.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 Hex=
  9. SET Hex.10=A
  10. SET Hex.11=B
  11. SET Hex.12=C
  12. SET Hex.13=D
  13. SET Hex.14=E
  14. SET Hex.15=F
  15.  
  16. :Loop
  17. SET /A "HexTmp = Num %% 16"
  18. IF %HexTmp% GTR 9 SET HexTmp=!Hex.%HexTmp%!
  19. SET /A Num /= 16
  20. SET Hex=%HexTmp%%Hex%
  21. IF %Num% GTR 0 GOTO Loop
  22.  
  23. ECHO.%Hex%
  24.  
  25. ENDLOCAL
  26. GOTO:EOF
  27.  
  28.  
  29. :Syntax
  30. ECHO.
  31. ECHO Num2Hex.bat,  Version 1.00 for Windows NT4 and later
  32. ECHO Convert the specified number to hexadecimal
  33. ECHO.
  34. ECHO Usage:  NUM2HEX  number
  35. ECHO.
  36. ECHO Where:  number   is a decimal or octal number
  37. ECHO                  (0nnn for octal)
  38. ECHO.
  39. ECHO Note:   Non-numeric input will be treated as 0
  40. ECHO.
  41. ECHO Written by Rob van der Woude
  42. ECHO http://www.robvanderwoude.com
  43.  
  44. IF "%OS%"=="Windows_NT" EXIT /B 1
  45.  

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