CT_SETBIT

 SETBIT()
 Sets one or more bits in a number
------------------------------------------------------------------------------
 Syntax

     SETBIT(<nLONG|cHexLONG>,<nBitPos1>,
        [<nBitPos32>]) --> nNewValue

 Arguments

     <nLONG|cHexLONG>  Designates either a decimal number or hexadecimal
     number string.

     <nBitPos1> ...  <nBitPos32>  Designates which bit numbers to
     set.

 Returns

     SETBIT() sets the designated bits and returns the result.

 Description

     For example, SETBIT() allows you to set one or more bits to change a
     serial interface register.  This is in contrast to NUMOR(), where the
     bit numbers can be set and do not need to be previously converted.  The
     value 1 represents the bit with the lowest value; 32 is the bit with the
     highest value.

 Note

     .  An invalid parameter returns a result of -1.

 Example

     Set bits 1, 2, and 5 in a numeric field:

     nBitfield  :=  0
     nBitfield  :=  SETBIT(nBitfield, 1, 2, 5)   // Result:  19

See Also: NUMAND() NUMNOT() NUMOR() NUMXOR() ISBIT()

 

CT_RANDOM

 RANDOM()
 Generates random numbers
------------------------------------------------------------------------------
 Syntax

     RANDOM([<lMode>]) --> nRandomWORD

 Argument

     <lMode>  Designates whether or not to return negative numbers.  The
     default creates only positive numbers.

 Returns

     RANDOM() returns a random number in the range of 0 to 65535 or when
     <lMode> is designated as .T., in the range of -32768 to +32767.

 Description

     RANDOM() produces random numbers to create a random distribution of test
     data for DEMO programs or any other application.

 Note

     .  If the <lMode> parameter is not specified, only positive
        numbers are returned.  When < lMode> is set to .T., the function
        returns the same number of positive and negative numbers.

 Examples

     .  Create a random number between 0 and 65535:

        ? RANDOM()

     .  Create a random number between 0 and 1:

        ? RANDOM()/65535

     .  Create a random whole number between 1 and 16:

        ? RANDOM()%16 +1

     .  Create a random number between -32768 and +32767:

        ? RANDOM(.T.)

See Also: RAND()

 

CT_RAND

 RAND()
 Generates random numbers
------------------------------------------------------------------------------
 Syntax

     RAND([<nStartValue>]) --> nRandomValue

 Argument

     <nStartValue>  Designates a beginning value for the random number
     generator.

 Returns

     RAND() returns a random number between 0 and 1.

 Description

     In contrast to RANDOM(), this function works with a seed algorithm.
     Multiple calls always returns the same random number sequence when it
     has the same start value.  When you first call RANDOM() without a
     parameter, it starts as if 100001 is specified as a parameter.
     Subsequent random numbers can then be influenced by the < nStartValue>.
     If this value is less than or equal to 0, the clock time is brought into
     the process.

     If you call the function with 100001 as a parameter, it allows you to
     restart the generator.  Then, if you call the function several times
     without parameter, it returns the "standard sequence" of numbers.

 Examples

     .  Call after program start:

        ? STR(RAND(), 18, 15)            // 0.831051100158447
        ? STR(RAND(), 18, 15)            // 0.557946857971956

     .  If the parameter equals 0, the clock time is incorporated.
        Even if the clock has not yet advanced, subsequent values are still
        different:

        ? STR(RAND(), 18, 15)            // Time dependent
        ? STR(RAND(), 18, 15)            // Subsequent time
                                         // dependent value

     .  Use a number greater than 0:

        ? STR(RAND(23), 18, 15)          // 0.121169930053736
        ? STR(RAND(23), 18, 15)          // 0.121169930053736

     .  Show a "new start":

        ? STR(RAND(100001), 18, 15)      // 0.831051100158447
        ? STR(RAND(), 18, 15)            // 0.557946857971956

See Also: RANDOM()

 

CT_NUMXOR

 NUMXOR()
 Performs a 16-bit "XOR" of two numbers
------------------------------------------------------------------------------
 Syntax

     NUMXOR(<nWORD1|cHexWORD1>,<nWORD2|cHexWORD2>)
         --> nWORD-XOR

 Argument

     <nWORD1|cHexWORD1> and <nWORD2|cHexWORD2>  Designates as either
     decimal numbers or hexadecimal digit strings.

 Returns

     The returned value corresponds to all the values designated as
     parameters joined with a logical exclusive OR.

 Description

     Only those bits that are different in the 2-bit fields and that you want
     to link together, are set to 1 in the result value.  Use NUMXOR() to
     encode smaller numbers.

 Note

     .  An invalid parameter returns a result of -1.

 Examples

     .  Link two numbers with NUMXOR():

        Value 1 in binary:      00000011
        Value 2 in binary:      00000101
                                ________
        The result: (6)         00000110
        ? NUMXOR(3, 5)                  // Result:  6

     .  Encode and decode numbers:

        ? NUMXOR(NUMXOR(nNumber, 9), 9)

See Also: NUMAND() NUMNOT() NUMOR() SETBIT() ISBIT()



CT_NUMROL

 NUMROL()
 Performs a 16-bit left rotation of a number
------------------------------------------------------------------------------
 Syntax

     NUMROL(<nWORD1|cHexWORD1>,<nWORD2|cHexWORD2>,
        [<lLowByte>]) --> nWORDLeft-Rotated

 Arguments

     <nWORD1|cHexWORD1>  Designates a numeric or hexadecimal value in the
     range of 0 to 65535.

     <nWORD2|cHexWORD2>  Designates a number of rotations in the range of
     1 to 15 (1 to 7); as either numeric or hexadecimal.

     <lLowByte>  If this optional parameter is designated as .T., then
     the low byte of the specified WORD is rotated.  The default is a 16-bit
     rotation (.F.).

 Returns

     NUMROL() returns the rotation result.

 Description

     This function rotates bits to the left in a number between 0 and 65535
     (16-bit value).  When the high bit rotates it is not just moved out to
     the left, it is also moved in on the right.  Use the optional logical
     parameter to determine if all 16 or only the low value 8 bits are to
     rotate.

 Notes

     .  If a value of > 15(7) is designated for <nWORD1|cHexWORD1>,
        the actual number of rotations for the remainder corresponds to a
        value divided by 16(8).

     .  A right rotation is also possible.  One rotation to the right
        corresponds to 15(or 7) rotations to the left, etc..

 Examples

     .  Rotate the 1 value three times to the left:

        00000000 00000001  00000000 00001000
        ? NTOC(1, 2, 16, "0"), NTOC(NUMROL(1, 3), 2, 16, "0")
                                         // Display as binary

     .  Value of 60000 -- only rotate the low 8-bit value:

        11101010 01100000  11101010 10000001
        NUMROL(60000, 2, .T.)

     .  Construct a rotation two places to the right:

        00000000 00000100  00000000 00000001
        ? NUMROL(4, 14)

     .  In parameter 2 > 15, there is only one rotation:

        ? NUMROL(1, 33)                  // Result:  2

See Also: NTOC()



CT_NUMOR

 NUMOR()
 Performs a 16-bit "OR" of a list of numbers
------------------------------------------------------------------------------
 Syntax

     NUMOR(<nWORD1|cHexWORD1>,<nWORD2|cHexWORD2>,
        [<nWORDncHexWORDn>]) --> nWORD-OR

 Argument

     <nWORD1|cHexWORD1>...<nWORDn|cHexWORDn>  Designates either decimal
     numbers or hexadecimal digit strings.

 Returns

     The returned value corresponds to all the values designated as
     parameters joined with a logical OR.

 Description

     NUMOR() allows you to target and set a single bit or multiple bits.  For
     example, use this to set a file attribute.

 Note

     .  An invalid parameter returns a result of -1.

 Example

     Set bit 5 in the MCR interface register of port 1, without changing any
     other bits:

     The register contains:      00000011
     The constant in binary:     00010000
                                 ________
     The result: (19)            00010011
     COM_MCR(1, NUMOR(COM_MCR(1), 16))

See Also: NUMAND() NUMNOT() NUMXOR() SETBIT() ISBIT()

 

CT_NUMNOT

 NUMNOT()
 Performs a 16-bit "NOT" of a number
------------------------------------------------------------------------------
 Syntax

     NUMNOT(<nWORD|cHexWORD>) --> nNegatedWORD

 Argument

     <nWORD|cHexWORD>  Designates either a decimal number or hexadecimal
     digit string.

 Returns

     NUMNOT() returns the negated binary value of the <.nWORD|cHexWORD>
     parameter.  The 0 bits become 1, and 1 bits become 0.

 Description

     This function is especially useful with file attributes, error codes,
     and when you manipulate bit fields.

 Notes

     .  The function returns the 1's complement of a number.

     .  An invalid parameter returns a result of -1.

 Example

     Show the 1's complement of a number:

     The number:         00000101  00000000
     The complement:     11111010  11111111
     ? NUMNOT(5)         // Result: 65530

See Also: NUMAND() NUMOR() NUMXOR() SETBIT() ISBIT()