Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: Hex Decimal conversion xHex
Use the StrFixLeft function to pad the hex string with zeros if a particular string size is desired.
#DefineFunction Dec2Hex(Dec) IsZero=@TRUE str="0123456789ABCDEF" hex="" for x=7 to 0 by -1 nibble= (dec >> (x*4)) & 15 if nibble==0 && IsZero==@TRUE then continue IsZero=@FALSE hex=strcat(hex,Strsub(str,nibble+1,1)) next return(hex) #EndFunction ;Example Usage a="2000" b=Dec2Hex(a) Message(a,b) ;Pad to 8 places b=strfixleft(b,0,8) Message(a,b)
#DefineFunction Dec2Hex(num) AddExtender("WWHUG34I.DLL") msvcrt = DllLoad("msvcrt.dll") two32 = huge_Multiply(4,2 ** 30) buffsize = 1000 buff = BinaryAlloc(buffsize) If num=="0" Then Return num _fmt = "" _nums = "" While num!="0" _x = ItemExtract(1,huge_Divide(num,two32),".") _fmt = StrCat("%%08X",_fmt) _nums = StrCat(",long:",huge_Subtract(num,huge_Multiply(_x,two32)),_nums) num = _x EndWhile BinaryEodSet(buff,DllCallCDecl(msvcrt,long:"sprintf",lpbinary:buff,lpstr:_fmt%_nums%)) Hex = BinaryPeekStr(buff,0,buffsize) BinaryFree(buff) DllFree(msvcrt) Return Hex #EndFunction Dec = "999999999999" Hex = Dec2Hex(Dec) Message(Dec,Hex)
Article ID: W14747
Filename: Decimal to Hex conversion.txt
File Created: 2010:05:18:12:35:56
Last Updated: 2010:05:18:12:35:56