Skip to content

Instantly share code, notes, and snippets.

@gabrielstelmach
Created June 22, 2023 19:28
Show Gist options
  • Save gabrielstelmach/c441fac56b4c56a448cee7b55e508317 to your computer and use it in GitHub Desktop.
Save gabrielstelmach/c441fac56b4c56a448cee7b55e508317 to your computer and use it in GitHub Desktop.
Batch script to convert decimal in hexa values
@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