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

WILX

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

xBaseConvert Issue

 Keywords: xBaseConvert Hex to Dec Decimal Hex2Dec huge large Integer huge_Multiply

Question:

I'm having problems using the "xBaseConvert" function for converting Hexadecimal to Decimal.

The following code returns -639. Using a Hex to Dec calculator, FFFFFD81 returns 4294966657

AddExtender("wilx44i.dll")   ;xBaseConvert
CurXOffset="FFFFFD81"
CurXOffset=xBaseConvert(CurXOffset, 16, 10)
Message("CurXOffset",CurXOffset)
Do you have any thoughts on what I could try to get the appropriate return?  The help file for that function says:


Answer:

xBaseConvert cannot handle a value of that size. You are dealing with a very large number. That number that is larger than can be handled by an integer data type. You will need to use the Huge Math extender to calculate this large of a value.
#DefineFunction Hex2Dec(hex)
   AddExtender("wwhug34i.dll") ; Huge Math Extender
   str="0123456789ABCDEF"
   hex=StrTrim(StrUpper(hex))
   hexlen=StrLen(hex)
   dec=0
   for x=1 to hexlen
          by16 = huge_Multiply(dec,16)
          ptr = StrIndex(str,strsub(hex,x,1),0,@fwdscan)-1
          dec = huge_Add( by16, ptr)
   next
   return(dec)
#EndFunction


;Example Usage
a="FFFFFD81"
b=Hex2Dec(a)
Message(a,b)
Exit


Article ID:   W17610
Filename:   xBaseConvert Issue.txt
File Created: 2012:11:26:09:51:24
Last Updated: 2012:11:26:09:51:24