CToN()

CToN()

Converts a numeric string into a different base

Syntax

       CToN( <xNumber>[, <nBase>][,<lMode>] ) -> <nInteger>

Arguments

<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.

Returns

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.

Description

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.

Notes

. The <cNumericstring> string is automatically TRIMmed left and right. . If you have invalid parameters or combinations, the function returns a value of 0.

Examples

       .  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

Platforms

All

Files

Source is numconv.prg, library is libct.

Seealso

NToC()

Advertisements

2 responses to “CToN()

  1. Pingback: Harbour Conversion Functions | Viva Clipper !

  2. Pingback: Harbour All Functions – C | Viva Clipper !

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s