Created
June 22, 2023 19:28
-
-
Save gabrielstelmach/c441fac56b4c56a448cee7b55e508317 to your computer and use it in GitHub Desktop.
Batch script to convert decimal in hexa values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off & setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION | |
set LOOKUP=0123456789abcdef &set HEXSTR=&set PREFIX= | |
if "%1"=="" echo 0&goto :EOF | |
set /a A=%* || exit /b 1 | |
if !A! LSS 0 set /a A=0xfffffff + !A! + 1 & set PREFIX=f | |
:loop | |
set /a B=!A! %% 16 & set /a A=!A! / 16 | |
set HEXSTR=!LOOKUP:~%B%,1!%HEXSTR% | |
if %A% GTR 0 goto :loop | |
echo %PREFIX%%HEXSTR% | |
goto :EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment