Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print the Hex value of a decimal number

Status
Not open for further replies.

dsandlin

Programmer
Joined
Jul 11, 2003
Messages
56
Location
CR
Someone asked me today how to convert a decimal number to hexadecimal in order to print it out, in VFP.

I found that the old faithful TRANSFORM function will do this nicely. If you print TRANSFORM(255, '@0'), you will get the string '0x000000FF', which is hex for 255.

I was a little surprised to learn that the HEX( ) function from VB isn't available in FoxPro, but you can build your own....
 
And, just because it belongs here, if you want to literally represent a number in hexadecimal, just start with "0x"... ie:

Code:
lnMyNumber = 0x0A
lnMyOtherNumber = 0xFF
* is equivalent to:
lnMyNumber = 10
lnMyOtherNumber = 0xFF

And, Just for Fun, This works:
Code:
xx=0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
(and, yes: precision is lost, though it seems that full precision is still maintained at:
xx=0xFFFFFFFFFFFFFFF
(just try adding "1" to it... it still is accurate) I didn't find the upper bound before precision is lost... probably in the VFP specs somewhere )
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top