CNV BIN


The CNV BIN instruction converts an alpha field containing a binary number to or from a numeric field. This may be useful when operating on single characters of alpha-type fields, such as when you want to convert an alpha field from lower case to upper case.

    ••••• CNV BIN  ••• •••••••••••••••••••••• ••• =  ••• •••••••••••••••••••••• •••
    (1)            (2) (3)                    (4)    (5) (6)                    (7)

(1) T/F execution conditions

(5) Source application ID

(2) Destination application ID

(6) Source field name, PDF, or constant

(3) Destination field name or PDF

(7) Source occurrence (constant/index)

(4) Destination occ (constant/index)

 

Using the Statement

If the source field is an alpha field, it is evaluated as a one-, two-, or four-byte binary value, depending on its length, and converted to the numeric destination field.

If the source field is a numeric field, its numeric value is converted into a one-, two-, or four-byte binary number, depending on the length of the destination field. The source field will be rounded to a whole number.

Restrictions

For an alpha source field, a numeric overflow condition occurs if the destination field is not large enough to store the converted value. The destination field must be numeric.

For a numeric source field, the destination must be alpha and between one, two, or four bytes in size. Based on the size of the destination field and the sign, the numeric value of the second field used in the conversion must be within the range specified below, or a numeric overflow condition occurs:

one byte signed:

-128 through +127

two bytes signed:

-32,768 through +32,767

four bytes signed:

-2,147,483,648 through +2,147,483,647

one byte unsigned:

0 through 255

two bytes unsigned:

0 through 65,535

four bytes unsigned:

0 through 4,294,967,295

Overflow processing is dependent on the use of OVERFLOW statements within the current event point.

Compilation Errors

The alpha field must be one, two, or four characters in length or a compile error occurs.

Related Statements

OVERFLOW

Example

The following example demonstrates how to convert an ASCII letter from lower case to upper case:

          CNV BIN  TAR WORK NUMBER                =  TAR ALPHA FIELD
          COMPUTE  TAR WORK NUMBER                -      32

          CNV BIN  TAR ALPHA FIELD                =  TAR WORK NUMBER

In this example, the alpha character is converted into a binary number (WORK NUMBER); then, the decimal value of 32 is subtracted from the field, producing the binary value of an uppercase letter. Finally, this value is converted back to its alpha representation.