Code: Select all
@echo off
:start
set /p dec=Enter Decimal Number to Convert :
call :toHex %dec%
echo converted decimal # = %hex%
goto start
goto :EOF
:toHex dec hex
::$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,2) 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
When I execute the above code this is what I get:
Enter Decimal Number to Convert : 16
10
converted decimal # =
How can I get the "hex" variable to return a value outside of the toHex function?
Thanks