Difference between revisions of "CVI"

From QB64 Wiki
Jump to navigation Jump to search
imported>Cyperium
Line 8: Line 8:
Numeric values read in from a random-access disk file must be converted from strings back into numbers if they are to be arithmetically manipulated.
Numeric values read in from a random-access disk file must be converted from strings back into numbers if they are to be arithmetically manipulated.


CVI converts a 2-byte string to an integer. MKI$ is its complement.
CVI converts a 2-byte string to an integer. [[MKI$]] is its complement.


CVS converts a 4-byte string to a single-precision number. MKS$ is its complement.
[[CVS]] converts a 4-byte string to a single-precision number. [[MKS$]] is its complement.


CVD converts an 8-byte string to a double-precision number. MKD$ is its complement.
[[CVD]] converts an 8-byte string to a double-precision number. [[MKD$]] is its complement.


(See MKI$, MKS$, and MKD$).
(See [[MKI$]], [[MKS$]], and [[MKD$]]).


Examples:
Examples:


  FIELD #1, 4 AS N$, 12 AS B$...
  [[FIELD]] #1, 4 [[AS]] N$, 12 [[AS]] B$...
  GET #1
  GET #1
  Y=CVS(N$)
  Y=[[CVS]](N$)


Line 80 reads a field from file #1, and converts the first four bytes (N$) into a single-precision number assigned to the variable Y.
Line 80 reads a field from file #1, and converts the first four bytes (N$) into a single-precision number assigned to the variable Y.


Since a single-precision number can contain as many as seven ASCII characters (seven bytes), writing a file using MKS$ conversion, and reading with the CVS conversion, as many as three bytes per numbe r recorded are saved on the storage medium. Even more may be saved if double-precision numbers are required. MKD$ and CVD conversions would be used in this case.
Since a single-precision number can contain as many as seven ASCII characters (seven bytes), writing a file using MKS$ conversion, and reading with the CVS conversion, as many as three bytes per numbe r recorded are saved on the storage medium. Even more may be saved if double-precision numbers are required. MKD$ and CVD conversions would be used in this case.

Revision as of 15:20, 5 September 2009

Purpose: To convert string values to numeric values.

Syntax: CVI(2-byte string)

Comments: Numeric values read in from a random-access disk file must be converted from strings back into numbers if they are to be arithmetically manipulated.

CVI converts a 2-byte string to an integer. MKI$ is its complement.

CVS converts a 4-byte string to a single-precision number. MKS$ is its complement.

CVD converts an 8-byte string to a double-precision number. MKD$ is its complement.

(See MKI$, MKS$, and MKD$).

Examples:

FIELD #1, 4 AS N$, 12 AS B$...
GET #1
Y=CVS(N$)

Line 80 reads a field from file #1, and converts the first four bytes (N$) into a single-precision number assigned to the variable Y.

Since a single-precision number can contain as many as seven ASCII characters (seven bytes), writing a file using MKS$ conversion, and reading with the CVS conversion, as many as three bytes per numbe r recorded are saved on the storage medium. Even more may be saved if double-precision numbers are required. MKD$ and CVD conversions would be used in this case.