Wilson WindowWare Tech Support

WinBatch WinBatch+Compiler WebBatch
Home | Tech Database | Tech BBS | White Papers | Purchase


Decimal to Hex conversion

 Keywords:  Hex Decimal conversion xHex

This UDF is nice for Decimal to Hex conversions when one does not wish the additional baggage of the WILX extender.

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)



Article ID:   W14747
Filename:   Decimal to Hex conversion.txt