^B
Interpret a string as a binary number
WSupported on Windows
|
USupported on Unix
|
VSupported on OpenVMS
|
NSupported in Synergy .NET
|
binary = ^B(expression[, size])
Return value
binary
The integer value of an alpha expression, evaluated as a binary number. If expression is null, the result is 0. (i)
Arguments
expression
The alpha expression to interpret as binary. (a)
size
(optional) A value that specifies the size of the resulting integer:
1 = i1 value
2 = i2 value
4 = i4 value
8 = i8 value
Discussion
If expression does not contain only valid binary digits (0 and 1), a “Binary digits expected in argument (string)” error ($ERR_BDIGXP) is generated.
By default, ^B produces an i4 value if the return value fits in 32 bits or an i8 value if the return value is larger than 32 bits. If size is specified, the value is returned in an integer of that size. If the value exceeds the specified size, it is truncated to fit. When used as the initial value of an automatically sized integer field, the field size is determined by the magnitude of the ^B result, not the size returned by ^B .
A ^B value that fits in 32 bits but has the high bit set will be negative. If you want a positive value when a negative i4 would normally be returned, specify a value of 8 in the optional size argument.
The integer return value is of the same endian type as the executing machine. If data is to be packed and stored, then retrieved in this way, and you want to function in a multiplatform environment, your code must take this into account. Data stored on disk files should be converted to portable integer format. See %CNV_IP and %CNV_PI for more information. |
Examples
The example below gets binary data for a record and stores it as bit flags.
subroutine get_flags a_bit_flags ,i external function yesno ,d record flags public ,d1 domestic ,d1 less50 ,d1 vmail ,d1 proc public = %yesno("Public company?") domestic = %yesno("Domestic sales only?") less50 = %yesno("Less than 50 employees?") vmail = %yesno("Voice mail system?") a_bit_flags = ^b(flags) xreturn endsubroutine function yesno a_txt ,a record yesno ,a1 proc display(TTCHN, a_txt, " (Y/N) ") reads(TTCHN, yesno) freturn (yesno .eq. 'Y') endfunction