Converts a numeric string into a different base

         --> nInteger


     <cNumericstring> Designates a numeric string to convert into a
     number in base <nBase>.

     <nBase>  Designates the number base to use in the conversion.  Can
     be in the range of 2 to 36.  The default is the decimal system, base 10.

     <lMode>  When designated as .T., allows a negative result.  The
     default allows only positive results.


     CTON() returns the converted number that corresponds to the string.  The
     values lie in the range of 0 and 65535 or, if <lMode> is .T., in the
     range of -32768 and +32767.


     CTON() offers a number of ways to covert a number string into numeric
     data format.  Almost any number can be converted, as long as the base
     <nBase>  for the number system lies between 2 and 36.


     .  The <cNumericstring> string is automatically TRIMmed left and

     .  If you have invalid parameters or combinations, the function
        returns a value of 0.


     .  Convert to base 10:

        ? CTON("60000")                    // Result:  60000

     .  Convert to base 2:

        ? CTON("11", 2)                    // Result:  3

        ? CTON("1110101001100000", 2)      // Result:  60000

     .  Convert to base 16:

        CTON("A", 16)                      // Result:  10

        ? CTON("ABCD", 16)                 // Result:  43981

        ? CTON("FFFF", 16, .T.)            // Result:  -1

     .  Convert to base 36:

        ? CTON("XXP", 36)                  // Result:  43981

See Also: NTOC()


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.