CVL: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
(Created page with "The CVL function decodes a 4-byte STRING generated by MKL$ (or read from a file) to LONG numeric values. {{PageSyntax}} : {{Parameter|result&}} = CVL({{Parameter|stringData$}}) {{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 wh...")
 
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 15: Line 15:
{{PageExamples}}
{{PageExamples}}
''Example 1: 4 byte [[ASCII]] character strings show how CVL multipliers convert [[MKL$]] values into a 4 byte [[LONG]] value.
''Example 1: 4 byte [[ASCII]] character strings show how CVL multipliers convert [[MKL$]] values into a 4 byte [[LONG]] value.
{{CodeStart}} '' ''
{{CodeStart}}
{{Cl|PRINT}} {{Cl|CVL}}({{Cl|CHR$}}(1) + {{Cl|STRING$}}(3, 0)) '{{Cl|ASC}}(CHR$(1)) * 1 = 1
{{Cl|PRINT}} {{Cl|CVL}}({{Cl|CHR$}}(1) + {{Cl|STRING$}}(3, 0)) '{{Cl|ASC (function)|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|CHR$}}(0) + {{Cl|CHR$}}(1) + {{Cl|STRING$}}(2, 0)) '{{Cl|ASC (function)|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$}}(2, 0) + {{Cl|CHR$}}(1) + {{Cl|CHR$}}(0)) '{{Cl|ASC (function)|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 '' ''
{{Cl|PRINT}} {{Cl|CVL}}({{Cl|STRING$}}(3, 0) + {{Cl|CHR$}}(1)) '{{Cl|ASC (function)|ASC}}(CHR$(1)) * 256 * 256 * 256 = 16777216
{{CodeEnd}}
{{CodeEnd}}




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


{{PageSeeAlso}}
{{PageSeeAlso}}
* [https://qb64phoenix.com/forum/showthread.php?tid=1066 Featured in our "Keyword of the Day" series]
* [[MKD$]], [[MKI$]], [[MKS$]], [[MKL$]], [[MKDMBF$]], [[MKSMBF$]]
* [[MKD$]], [[MKI$]], [[MKS$]], [[MKL$]], [[MKDMBF$]], [[MKSMBF$]]
* [[CVI]], [[CVS]], [[CVD]], [[CVDMBF]], [[CVSMBF]]
* [[CVI]], [[CVS]], [[CVD]], [[CVDMBF]], [[CVSMBF]]

Latest revision as of 19:28, 24 May 2024

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:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link