CVD: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
(Created page with "The CVD function decodes an 8-byte STRING generated by MKD$ (or read from a file) to DOUBLE numeric values. {{PageSyntax}} : {{Parameter|result#}} = CVD({{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$). * Variables of numerical types are also encoded...")
 
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 15: Line 15:
{{PageExamples}}
{{PageExamples}}
''Example 1:'' Reading an 8-byte encoded string n$ from a file and obtaining the decoded [[DOUBLE]] value:
''Example 1:'' Reading an 8-byte encoded string n$ from a file and obtaining the decoded [[DOUBLE]] value:
{{CodeStart}} '' ''
{{CodeStart}}
{{Cl|FIELD}} #1, 8 {{Cl|AS}} N$, 12 {{Cl|AS}} B$...
{{Cl|FIELD}} #1, 8 {{Cl|AS}} N$, 12 {{Cl|AS}} B$...
{{Cl|GET}} #1
{{Cl|GET}} #1
Y# = {{Cl|CVD}}(N$) '' ''
Y# = {{Cl|CVD}}(N$)
{{CodeEnd}}
{{CodeEnd}}
: ''Explanation:'' Reads a field from file #1, and converts the first eight bytes (N$) into an double-precision number assigned to the variable Y#.
: ''Explanation:'' Reads a field from file #1, and converts the first eight bytes (N$) into an double-precision number assigned to the variable Y#.
Line 42: Line 42:


{{PageSeeAlso}}
{{PageSeeAlso}}
{{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]], [[CVL]], [[CVSMBF]], [[CVDMBF]]
* [[CVI]], [[CVS]], [[CVL]], [[CVSMBF]], [[CVDMBF]]

Latest revision as of 19:27, 24 May 2024

The CVD function decodes an 8-byte STRING generated by MKD$ (or read from a file) to DOUBLE numeric values.


Syntax

result# = CVD(stringData$)


Description


Examples

Example 1: Reading an 8-byte encoded string n$ from a file and obtaining the decoded DOUBLE value:

FIELD #1, 8 AS N$, 12 AS B$...
GET #1
Y# = CVD(N$)
Explanation: Reads a field from file #1, and converts the first eight bytes (N$) into an double-precision number assigned to the variable Y#.


Example 2: Showcases the reduced space to store an encoded number.

a# = 77000.24523213
PRINT "Value of a#:"; a#
b$ = MKD$(a#)
PRINT "Value of a# encoded using MKD$: "; b$
PRINT "The string above, decoded using CVD:"; CVD(b$)
Value of a#: 77000.24523213

Value of a# encoded using MKD$: ñåxýâ╠‗@

The string above, decoded using CVD: 77000.24523213
Since the representation of a double-precision number can use up to 15 ASCII characters (fifteen bytes), writing to a file using MKD$ conversion, and then reading back with the CVD conversion can save up to 7 bytes of storage space.


See also

See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link