WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Conversion UDFs

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

UDS - udsDec2Hex

 Keywords: Dec Decimal to 2 Hex Hexidecimal Convert Conversion UDF UDS Huge Numbers Large 

Developer: snowsnowsnow 03/12/2008

hex2dec sample that should handle any number, subject to these limits:

  1. The limits of the huge math extender
  2. The command line length limit (currently 2048) - since it uses % sub trickery. This trickery could, of course, be removed, but I like it the way it is.
  3. The arbitrarily set buffer size (1000).
Sample usage: bighex.wbt 12,345,678,901,234,567,890 ,
; vim:fo-=t fo+=ro1 comments+=b\:;
IntControl(50,0,0,0,0)          ; Turn off Web Page Support
AddExtender("wwhug34i.dll")

#DefineSubroutine udsDec2Hex(num,sep)
IF num == "0" THEN Return num
_fmt = ""
_nums = ""
WHILE num != "0"
    _x = ItemExtract(1,huge_Divide(num,two32),".")
    _fmt = StrCat(sep,"%%08X",_fmt)
    _nums = StrCat(",long:",huge_Subtract(num,huge_Multiply(_x,two32)),_nums)
Pause("Debug",StrCat("num = ",num,"%@CRLF%_x = ",_x,"%@CRLF%_nums = ",_nums,"%@CRLF%_fmt = ",_fmt))
    num = _x
ENDWHILE
BinaryEodSet(buff,DllCallCdecl(msvcrt,long:"sprintf",lpbinary:buff,lpstr:_fmt%_nums%))
Return BinaryPeekStr(buff,StrLen(sep),buffsize)
#EndSubroutine

buffsize = 1000
buff = BinaryAlloc(buffsize)
msvcrt = DllLoad("msvcrt.dll")
two32 = huge_Multiply(4,2**30)
IF !IsDefined(Param1) THEN Param1 = "7888627066"
IF !IsDefined(Param2) THEN Param2 = ""
Pause("Result:",udsDec2Hex(StrReplace(Param1,",",""),Param2))

Article ID:   W17480
File Created: 2008:04:10:15:11:24
Last Updated: 2008:04:10:15:11:24