Difference between revisions of "CVL"

From QB64 Wiki
Jump to navigation Jump to search
imported>Clippy
imported>SMcNeill
(style guidelines)
 
(14 intermediate revisions by one other user not shown)
Line 1: Line 1:
'''Purpose:'''
The [[CVL]] function decodes a 4-byte [[STRING]] generated by [[MKL$]] (or read from a file) to [[LONG]] numeric values.
To convert string values to numeric values.


'''Syntax:'''
CVL(''4-byte string'')


'''Comments:'''
{{PageSyntax}}
* 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.
: {{Parameter|result&}} = [[CVL]]({{Parameter|stringData$}})


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


* [[CVS]] converts a 4-byte string to a [[SINGLE]]-precision number. [[MKS$]] is its complement.
{{PageDescription}}
* ''CV'' functions ([[CVD]], [[CVS]], [[CVI]], [[CVL]], [[CVDMBF]], [[CVSMBF]]) are used to convert values encoded by ''MK$'' functions ([[MKD$]], [[MKS$]], [[MKI$]], [[MKL$]], [[MKDMBF$]], [[MKSMBF$]]).
* '''QB64''' has [[_CV]] and [[_MK$]] functions which can also deal with extended [[Data types|data types]].
* [[LONG]] values can range from -2147483648 to 2147483647.
* Doesn't return [[_UNSIGNED]] values.


* CVL converts a 4 byte string to a [[LONG]] integer number. [[MKL$]] is its compliment.


* [[CVD]] converts an 8-byte string to a [[DOUBLE]]-precision number. [[MKD$]] is its complement.
{{PageExamples}}
''Example 1: 4 byte [[ASCII]] character strings show how CVL multipliers convert [[MKL$]] values into a 4 byte [[LONG]] value.
{{CodeStart}} '' ''
{{Cl|PRINT}} {{Cl|CVL}}({{Cl|CHR$}}(1) + {{Cl|STRING$}}(3, 0)) '{{Cl|ASC}}(CHR$(1)) * 1 = 1
{{Cl|PRINT}} {{Cl|CVL}}({{Cl|CHR$}}(0) + {{Cl|CHR$}}(1) + {{Cl|STRING$}}(2, 0)) '{{Cl|ASC}}(CHR$(1)) * 256 = 256
{{Cl|PRINT}} {{Cl|CVL}}({{Cl|STRING$}}(2, 0) + {{Cl|CHR$}}(1) + {{Cl|CHR$}}(0)) '{{Cl|ASC}}(CHR$(1)) * 256 * 256 = 65536
{{Cl|PRINT}} {{Cl|CVL}}({{Cl|STRING$}}(3, 0) + {{Cl|CHR$}}(1)) '{{Cl|ASC}}(CHR$(1)) * 256 * 256 * 256 = 16777216 '' ''
{{CodeEnd}}


* CV functions cannot be used to convert any values but MK function values!


''Example 2:''
{{CodeStart}} '' ''
{{Cl|FIELD}} #1, 4 {{Cl|AS}} N$, 12 {{Cl|AS}} B$...
{{Cl|GET}} #1
Y& = {{Cl|CVL}}(N$) '' ''
{{CodeEnd}}
:''Explanation:'' Reads a field from file #1, and converts the first four bytes (N$) into a long integer value assigned to the variable Y&.


:Since the representation of a long number can use up to 10 ASCII characters (ten bytes), writing to a file using [[MKL$]] conversion, and then reading back with the [[CVL]] conversion can save up to 6 bytes of storage space.


''Examples:''


: [[FIELD]] #1, 4 [[AS]] N$, 12 [[AS]] B$...
{{PageSeeAlso}}
: [[GET]] #1
* [[MKD$]], [[MKI$]], [[MKS$]], [[MKL$]], [[MKDMBF$]], [[MKSMBF$]]
: Y& = [[CVL]](N$)
* [[CVI]], [[CVS]], [[CVD]], [[CVDMBF]], [[CVSMBF]]
* [[_CV]], [[_MK$]]


''Explanation:''


:Reads a field from file #1, and converts the first four bytes (N$) into a long integer number assigned to the variable Y&.
{{PageNavigation}}
 
:Since a long number can contain as many as ten ASCII characters (ten bytes), writing a file using [[MKL$]] conversion, and reading with the CVL conversion, as many as six bytes per number recorded are saved on the storage medium.
 
 
''See also:'' [[MKI$]], [[MKS$]], [[MKL$]], [[MKD$]], [[Bitmaps]]
 
 
 
 
==Navigation:==
 
[[Keyword_Reference_-_Alphabetical|Go to Keyword Reference - Alphabetical]]
 
[[Keyword Reference - By usage|Go to Keyword Reference - By usage]]

Latest revision as of 14:19, 11 September 2017

The CVL function decodes a 4-byte STRING generated by MKL$ (or read from a file) to LONG numeric values.


Syntax

result& = CVL(stringData$)


Description


Examples

Example 1: 4 byte ASCII character strings show how CVL multipliers convert MKL$ values into a 4 byte LONG value.

PRINT CVL(CHR$(1) + STRING$(3, 0)) 'ASC(CHR$(1)) * 1 = 1 PRINT CVL(CHR$(0) + CHR$(1) + STRING$(2, 0)) 'ASC(CHR$(1)) * 256 = 256 PRINT CVL(STRING$(2, 0) + CHR$(1) + CHR$(0)) 'ASC(CHR$(1)) * 256 * 256 = 65536 PRINT CVL(STRING$(3, 0) + CHR$(1)) 'ASC(CHR$(1)) * 256 * 256 * 256 = 16777216


Example 2:

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

Explanation: Reads a field from file #1, and converts the first four bytes (N$) into a long integer value assigned to the variable Y&.
Since the representation of a long number can use up to 10 ASCII characters (ten bytes), writing to a file using MKL$ conversion, and then reading back with the CVL conversion can save up to 6 bytes of storage space.


See also



Navigation:
Keyword Reference - Alphabetical
Keyword Reference - By Usage
Main Wiki Page