How To Convert Values to Hexadecimal Format with Xbase

Last reviewed: January 10, 1997
Article ID: Q155389
The information in this article applies to:
  • Microsoft Visual FoxPro for Windows, version 5.0

SUMMARY

Visual FoxPro 5.0 allows you to convert between hexadecimal and decimal values using Xbase code.

MORE INFORMATION

Visual FoxPro 5.0 helps you easily convert between decimal and hexadecimal numbers. The following examples demonstrate how to gain decimal output from a hexadecimal number. Type the following lines in the Command window:

   x = 0xff
   WAIT WINDOW STR(x)
   y = 0xefff
   WAIT WINDOW STR(y)

The WAIT WINDOW commands report the numbers 255 and 61439. The zero and the x (0x) in front of the hexadecimal value tells Visual FoxPro to treat the proceeding values as hexadecimal values.

Additionally, the TRANSFORM() function has a new clause to handle hexadecimal conversions. The following TRANSFORM() functions demonstrate this new functionality. Type the following code in the Command window:

   ? TRANSFORM(x,"@0")
   ? TRANSFORM(y,"@0")

The TRANSFORM() function converts the decimal values back to hexadecimal form. The zero (0) format code directs the TRANSFORM() function to output hexadecimal numbers. The output is always an eight-digit hexadecimal value preceded by 0x.

While these new capabilities are easy to use, earlier versions of FoxPro do not have this functionality. If you need backward-compatible code that converts decimals to hexadecimal values, create a function within Visual FoxPro using the CONVERT() function.

For more information about this technique, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q95717
   TITLE     : How to Convert Decimal Numbers to Hexadecimal Numbers


KBCategory: kbprg kbhowto
KBSubcategory: FxprgGeneral
Additional reference words: 5.00 kbdsd vfoxwin



THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: January 10, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.