| Description: |
call:toHex dec hex |
| Script: |
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18.
|
:toHex dec hex -- convert a decimal number to hexadecimal
:: -- dec [in] - decimal number to convert
:: -- hex [out,opt] - variable to store the converted hexadecimal number in
:$created 20091203 :$changed 20091203 :$categories Arithmetic,Encoding
:$source http://www.dostips.com
SETLOCAL ENABLEDELAYEDEXPANSION
set /a dec=%~1
set "hex= "
SET "map=0-0;1-1;2-2;3-3;4-4;5-5;6-6;7-7;8-8;9-9;10-A;11-B;12-C;13-D;14-E;15-F"
for /L %%N in (1,1,8) do (
set /a d=dec%%16,dec/=16
call set h=%%map:*!d!-=%%
set hex=!h:~0,1!!hex!
)
( ENDLOCAL & REM RETURN VALUES
IF "%~2" NEQ "" (SET %~2=%hex%) ELSE ECHO.%hex%
)
EXIT /b
|
|