HTBasic Help
×
Menu
Index

FORMAT Options

 
One piece of information stored in the I/O path is whether to transfer information in ASCII or binary (internal) format. ASCII transfers are called FORMAT-ON-format and binary transfers are called FORMAT-OFF-format. If FORMAT is not explicitly specified in the ASSIGN statement, a default format is used. For interfaces, buffers, devices, and LIF ASCII files the default is FORMAT ON; for BDAT and regular files, the default is FORMAT OFF.
 
This example explicitly specifies FORMAT ON:
 
10   ASSIGN @George TO "TEMP.TXT";FORMAT ON
 
When FORMAT ON is specified in the ASSIGN statement, data items are output in a readable ASCII format. Numeric items are output in the standard ASCII numeric format and the ASCII characters in a string are output. If the default output formats are not acceptable, the USING and IMAGE statements can be used to format the data as needed.
 
When FORMAT ON is specified, data items are entered with the data expected to be in readable ASCII format. Reading data with FORMAT ON works with most devices. For other devices, most formats can be handled using IMAGE and USING statements. Numeric data must be scanned to find legal combinations of characters that make up a numeric value. String data must be scanned for end-of-string terminators.
 
When FORMAT OFF is specified in the ASSIGN statement, data is transferred in internal format. LSB/MSB FIRST can be used in the ASSIGN statement to specify the order in which the data bytes are sent or received. If LSB/MSB FIRST is not specified, data sent to devices is sent MSB FIRST for compatibility with HP devices; data sent to files, and operating system devices is stored in the form most natural to the computer’s processor. Of course, LSB/MSB FIRST can always be used to override these defaults.
 
20   ASSIGN @Dev1 TO 9;FORMAT LSB FIRST
 
The internal format for INTEGER numbers is a two byte, two’s complement, binary integer. The internal format for LONG (integer) numbers is four byte, two’s complement, binary integer. The internal format for REAL numbers is an eight byte, IEEE compatible floating point number (see IEEE Standard for Binary Floating-Point Arithmetic, ANSI/IEEE Std. 754-1985). The internal format for COMPLEX numbers is two real numbers. The first eight bytes contain the real part of the number and the last eight bytes contain the imaginary part.
 
The format for strings depends on the source or destination of the I/O statement. For regular files the internal format for strings is a null-terminated string.
The string format for devices and BDAT files consists of a four-byte-integer string length followed by the string contents. An even number of bytes is always transferred, therefore, if the string is odd in length an extra pad byte is transferred. The LSB/MSB FIRST option can be used to determine the byte ordering of the four byte string length.
 
For LIF ASCII files FORMAT OFF has no effect. Data is always transferred as ASCII strings proceeded by a two byte integer length and padded by a trailing space if necessary to make the string length even. The string length is always transferred with MSB FIRST.