Freitag, 28. März 2008

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).
:: 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.

Reflog

Informationstechnische Howtos, Hinweise und Merkwürdiges

Batchlib v1.0 2008-03-29

Aktuelle Beiträge

HOWTO_ O2 DSL Surf &...
Der O2 DSL Surf & Phone-Router ist für die...
cypressor - 12. Feb, 19:57
Uptweak Windows XP Home...
There are a lot of annoying limitations in Windows...
cypressor - 9. Okt, 19:30
BATCHLIB_ Batchlib package...
Download Batchlib package v1.0 (5 KB zip file) What...
cypressor - 29. Mrz, 19:10
BATCHLIB_ Batchlib library...
The batchlib library string.cmd is part of the batchlib...
cypressor - 29. Mrz, 18:10

Homepage Ticker

Links

Status

Online seit 4256 Tagen
Zuletzt aktualisiert: 28. Jun, 11:32
RSS XML 1.0 Button-Get-Firefox

batch
batchlib
howto
tech
video
Profil
Abmelden
Weblog abonnieren