BATCH_ Convert decimal number to hex string
Though hex numbers can be converted to decimals using SET /A MY_DECIMAL=0xFF, the other way around is not natively supported in Windows batch. However, the following subroutine does this job for numbers 0 <= x <= 255 (8bit).
Note: This subroutine is part of the number.cmd library contained in the batchlib package since version 1.0.
:: Converts a decimal number to hex. Currently only numbers 0 <= x <= 255 are :: supported (0x00 <= x <= 0xFF). The result will NOT be prefixed with 0x! :: :: @PARAM Integer decimal number 0 <= x <= 255 :: @RETURN String hex representation of number :: @SINCE 1.0 :DEC2HEX SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION SET HEX=0123456789ABCDEF SET /A T1=%1 / 16 SET /A T2=%1 %% 16 SET RESULT=!HEX:~%T1%,1!!HEX:~%T2%,1! ENDLOCAL & SET RESULT=%RESULT% GOTO :EOF
Note: This subroutine is part of the number.cmd library contained in the batchlib package since version 1.0.
cypressor - 28. Mär, 20:49