CTOBIN( ) Function

Converts a binary character representation to a numeric value.

CTOBIN(cExpression [, cFlags])

Parameters

  • cExpression
    Specifies the binary character representation to convert.

  • cFlags
    If the binary character representation specified with cExpression was generated using an 8 byte data type (currency or double, for example), include cFlags to control the type of value returned by CTOBIN( ).

    cFlags

    Description

    1

    cExpression is an expression that is 1 byte long.

    2

    cExpression is an expression that is 2 bytes long.

    4

    cExpression is an expression that is 4 bytes long.

    8

    cExpression is an expression that is 8 bytes long.

    B

    cExpression is a double data type, and must be 8 bytes long.

    CTOBIN( ) returns a double data type value. This is the default for an expression that is 8 bytes long.

    N

    cExpression is a numeric data type, and must be 4 or 8 bytes long.

    CTOBIN( ) returns a numeric type value.

    Y

    cExpression is a currency data type, and must be 8 bytes long.

    CTOBIN( ) returns a currency type value.

    R

    Reverses the binary expression.

    S

    Prevents the sign bit of number from being toggled (BITXOR).

Return Value

Numeric. CTOBIN( ) returns a numeric value from a binary character expression.

Remarks

The cFlags parameter is a character expression. The 'R' and 'S' settings are additive while the others are mutually exclusive. Character settings can be passed in either upper or lower case (e.g., 'R' or 'r'). Specifying a value of '1', '2' or '4' is not required, but is available as a convenience to provide feedback for the length of cExpression.

The following examples show various uses of the cFlags parameter.

? CTOBIN("A")&& same as CTOBIN("A","1")
? CTOBIN(BINTOC($12.34,"8"),"Y")
? CTOBIN(BINTOC(12.34,"8"),"B")
? CTOBIN(BINTOC(PI(),"BR"),"NRS")

You can use CTOBIN( ) to convert a binary character representation created with BINTOC( ) to its integer value. CTOBIN( ) can also be used when working with Win32 API routines where you might need to convert to or from a Win32 struct member. The 'R' and 'S' settings allow you to use CTOBIN ( ) to work more efficiently with these scenarios.

See Also

Tasks

Create Small Indexes Using BINTOC( ) Sample

Reference

BINTOC( ) Function

CREATEBINARY( ) Function

Visual FoxPro Data and Field Types

Other Resources

Functions