A bit constant is a binary, octal, or hexadecimal constant. It can appear wherever numeric constants are allowed.
A bit constant has no type. It assumes a numeric data type and size within the context in which it is used.
A binary constant is a string of binary (base 2) digits (0 or 1) enclosed by apostrophes and followed by the letter B.
This constant is a representation of a numeric constant, and takes the following form:
'c1c2c3 . . . cn'B
You can specify up to 128 binary digits in a binary constant. Leading zeros are ignored.
The following examples show valid and invalid binary constants:
Valid | |
'0101110'B | |
'1'B | |
Invalid | Explanation |
'0112'B | The character 2 is invalid |
10011'B
| No initial apostrophe |
'1000001' | No B after second apostrophe |
Octal and Hexadecimal Constants
Octal and hexadecimal constants are alternative ways to represent numeric constants, and are described as follows:
'c1c2c3 . . . cn'O
'c1c2c3 . . . cn'X 'c1c2c3 . . . cn'Z
Leading zeros are ignored in octal and hexadecimal constants. You can specify up to 128 bits (43 octal digits, 32 hexadecimal digits).
The following examples show valid and invalid octal and hexadecimal constants:
Octal Constants | |
---|---|
Valid | |
'07737'O | |
'1'O | |
Invalid | Explanation |
'7782'O |
The character 8 is invalid |
7772'O | No initial apostrophe |
'0737'
| No O after second apostrophe |
Hexadecimal Constants | |
Valid | |
'AF9730'X | |
'FFABC'X | |
'84'Z | |
Invalid | Explanation |
'999.'X | Decimal not allowed |
'F9X |
No apostrophe before X |
Bit constants have no data type until they are used. When used, they assume a data type based on their use.
When the bit constant is used with a binary operator, including the assignment operator, the data type of the constant is the data type of the other operand; for example:
Statement | Data Type of Constant | Length of Constant (in bytes) |
---|---|---|
INTEGER*2 ICOUNT |
||
REAL*8
DOUBLE | ||
REAL RAFFIA |
||
RAFFIA =
'100110011111100100011'B | REAL*4 | 4 |
RAFFIA = '99AF2'X
| REAL*4 | 4 |
DOUBLE = '111111111111100110011010'B |
REAL*8 | 8 |
DOUBLE =
'FFF99A'X | REAL*8 | 8 |
JCOUNT = ICOUNT + '011101110111'B
| INTEGER*2 | 2 |
JCOUNT = ICOUNT + '777'O |
INTEGER*2 | 2 |
IF (N .EQ. '1010100'B) GO TO 10 |
INTEGER*4 | 4 |
IF
(N .EQ. '123'O) GO TO 10 | INTEGER*4 | 4 |
When a specific data type (generally integer) is required, that type is assumed for the bit constant. For example:
Statement | Data Type of Constant | Length of Constant (in bytes) |
---|---|---|
Y(IX) = Y('15'O) + 3. |
INTEGER*4 | 4 |
When a bit constant is used as an actual argument, the following occurs:
For example:
Statement | Data Type of Constant | Length of Constant (in bytes) |
---|---|---|
CALL APAC('34BC2'X) | VAX: None Alpha: INTEGER*4 | 4 |
When a bit constant is used in any other context, an INTEGER (INTEGER*4) data type is assumed (unless compiler option INTEGER_SIZE specifies otherwise). For example:
Statement | Data Type of Constant | Length of Constant (in bytes) |
---|---|---|
IF ('AF77'X) 1,2,3 |
INTEGER*4 | 4 |
I
= '7777'O - 'A39'X [1] | INTEGER*4 | 4 |
J = .NOT. '73777'O
| INTEGER*4 | 4 |
[1] When two typeless constants are used in an operation, they both take the INTEGER*4 data type. |
An octal or hexadecimal constant specifies up to 16 bytes of data. When the data type implies that the length of the constant is more than the number of digits specified, the leftmost digits have a value of zero. When the data type implies that the length of the constant is less than the number of digits specified, the constant is truncated on the left. An error results if any nonzero digits are truncated. Table 2-1 lists the number of bytes that each data type requires.