NTOC()

NTOC()

Converts the numbers in a digit string into a different number base

Syntax

       NTOC( <xNumber>[, <nBase>][,<nLength>][,<cPadChar>] ) -> <cNumber>

Arguments

<xNumber> Corresponds to a decimal number or hexadecimal character string to convert. <nBase> Designates the number system base, from 2 to 36 (inclusive), to use in the result. The default is the decimal system, base 10. <nLength> Designates the length of the string that results. The maximum length is 255. The default is the length required for the conversion. <cPadChar> Designates a pad character to pad the string result on the left. The default value is a space.

Returns

NTOC() returns a character string that contains the conversion result of <nLONG|cHexLONG> into the <nBase> number system.

Description

NTOC() converts a decimal number or hexadecimal string into a number string. The result is a number in base <nBase> or, if <nBase> is not specified, in base 10. Use <nLength> to determine the length of the result string. However, if <nLength> is longer than the length necessary for the result, the result string is padded on the left with spaces or with a character selected with <cPad>.

Note

. If incompatible parameter combinations are specified, NTOC() returns one or more asterisks (*) as a result.

Examples

       .  Convert to base 10:
              ? NTOC (60000)                //"60000"
              ? NTOC (60000, 10, 7)         //"    60000"
           .  Convert to base 2:
              ? NTOC(60000, 2)              // "1110101001100000"
              ? NTOC("FFFF", 2)             // "1111111111111111"
              ? NTOC("30", 2, 8, "0")       // "00110000"
           .  Convert to base 16:
              ? NTOC(43981, 16)             // "ABCD"
           .  Convert to base 36:
              ? NTOC(43981, 36, 4)          // "XXP"
           .  Invalid parameters (overflow):
              ? NTOC("GGGG", 2)             // "*"
              ? NTOC(60000, 10, 3)          // "***"
              ? NTOC(60000, 1, 4)           // "****"

Platforms

All

Files

Source is numconv.prg, library is libct.

Seealso

CTON()

Harbour All Functions – C

CD / CHDIR / DirChange

CDoW

Chr

CharAdd
CharAnd
CharEven
CharHist
CharList
CharMirr
CharMix
CharNoList
CharNot
CharOdd
CharOne
CharOnly
CharOr
CharPix
CharRela
CharRelRep
CharRem
CharRepl
CharRLL
CharRLR
CharSHL
CharSHR
CharSList
CharSort
CharSub
CharSwap
CharWin
CharXOR

CLIPINIT
CMonth

Col

Cos

CosH

CountLeft
CountRight

CToBit

CToD

CToDoW
CToF
CToMonth
CToN

CurDir

CSetArgErr
CSetAtMuPa
CSetRef
CTCExit
CTCInit
CTExit
CTInit

Conversion Functions

Harbour Conversion Functions

Bin2I Convert signed short encoded bytes into Harbour numeric
Bin2L Convert signed long encoded bytes into Harbour numeric
Bin2U Convert unsigned long encoded bytes into Harbour numeric
Bin2W Convert unsigned short encoded bytes into Harbour numeric
BitToC Converts position-dependent bits into characters
BinToDec Converts a Binary Value to Decimal
CToBit Converts a character string into a bit pattern
CToF Converts a special 8-byte string into a floating point number
CToN Converts a numeric string into a different base
DecToBin Converts a Decimal Value to Binary
DecToHexa Converts a Decimal Value to Hexa
DecToOctal Converts a Decimal Value to Octal
Fahrenheit Temperature conversion Celsius to Fahrenheit
FToC Converts a floating point number into a special 8-byte string
HexaToDec Converts a Hexa Value to Decimal
I2Bin Convert Harbour numeric into signed short encoded bytes
L2Bin Convert Harbour numeric into signed long encoded bytes
NToC Converts the numbers in a digit string into a different number base
OctalToDec Converts a Octal Value to Decimal
U2Bin Convert Harbour numeric into unsigned long encoded bytes
W2Bin Convert Harbour numeric into unsigned short encoded bytes
Word Converts double to integer values
XTOC Convert an expression to character type string

CT_CTON

 CTON()
 Converts a numeric string into a different base
------------------------------------------------------------------------------
 Syntax

     CTON(<cNumericstring>,[<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


See Also: NTOC()

 

Tools – Numbers/Bit Manipulation

Introduction
BITTOC()     Converts position-dependent bits into characters
CELSIUS()    Converts a Fahrenheit temperature value into Celsius
CLEARBIT()   Clears one or more bits within a number to zero
CTOBIT()     Converts a character string into a bit pattern
CTOF()       Converts a special 8-byte string into a floating point number
CTON()       Converts a numeric string into a different base
EXPONENT()   Determines the exponent of a floating point number (base 2)
FAHRENHEIT() Converts a temperature value from Celsius into Fahrenheit
FTOC()       Converts a floating point number into a special 8-byte string
INFINITY()   Creates the largest number possible (21023)
INTNEG()     Converts an unsigned integer into a signed integer
INTPOS()     Converts a signed integer into an unsigned integer
ISBIT()      Tests the bits in a number
LTON()       Converts a logical value into a numeric value
MANTISSA()   Determines the mantissa of a floating point number (base2)
NTOC()       Converts numbers in a digit string into a different number base
NUMAND()     Performs a 16-bit "AND" of a list of numbers
NUMCOUNT()   Uses the internal CA-Clipper Tools counter
NUMHIGH()    Returns the higher value byte in a 16-bit number
NUMLOW()     Returns the lower value byte in a 16-bit number
NUMMIRR()    Mirrors 8-bit or 16-bit values
NUMNOT()     Performs a 16-bit "NOT" of a number
NUMOR()      Performs a 16-bit "OR" of a list of numbers
NUMROL()     Performs a 16-bit left rotation of a number
NUMXOR()     Performs a 16-bit "XOR" of two numbers
RAND()       Generates random numbers
RANDOM()     Generates random numbers
SETBIT()     Sets one or more bits in a number

Hex View

Hexadecimal file viewer.

This is a experimental project with first intend of point out the power of Harbour and HMG. So, HexView is considerably slow on large files, please be patient.

Download here ( source only ).