Bit-String to Arithmetic Conversion

Bit-string to arithmetic conversion assigns a bit string to any arithmetic data type.

Bit-string to arithmetic conversion produces reasonable results and permits bit strings to be used to hold positive integers. However, because arithmetic operators require arithmetic operands, the BINARY or DECIMAL built-in function should be used to produce an explicit conversion of a bit-string value to a binary or decimal integer value.

The conversion is invalid if the length of the source bit string exceeds N where N is the maximum precision allowed by the implementation for fixed-point binary values. For the maximum precision allowed by Open PL/I, see your Open PL/I User's Guide.

If no target base or scale is given by the context that caused the conversion, fixed binary is supplied by default. If a target precision is not given, the maximum precision allowed for the target base and scale is supplied.

The rightmost bit of the source value is considered to be the units position of a positive binary integer value of precision p, where p is the length of the source bit-string value. The value of that binary integer is then converted to conform to the base, scale, and precision of the target using the normal rules for arithmetic to arithmetic conversion. A null bit-string value converts to zero, as shown in the following examples.

Source     Result
'101'B 5
"B 0
'0000'B 0