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()
Pingback: Harbour Conversion Functions | Viva Clipper !
Pingback: Harbour All Functions – C | Viva Clipper !