Wiki source for KeyPgCvi


Show raw source

{{fbdoc item="title" value="CVI"}}----
Converts a floating-point number or string to an integer variable using a binary copy

{{fbdoc item="syntax"}}##
32-bit:
[[KeyPgDeclare|declare]] [[KeyPgFunction|function]] **Cvi** ( [[KeyPgByval|byval]] //f// [[KeyPgAs|as]] [[KeyPgSingle|single]] ) [[KeyPgAs|as]] [[KeyPgInteger|integer]]
64-bit:
[[KeyPgDeclare|declare]] [[KeyPgFunction|function]] **Cvi** ( [[KeyPgByval|byval]] //f// [[KeyPgAs|as]] [[KeyPgDouble|double]] ) [[KeyPgAs|as]] [[KeyPgInteger|integer]]

[[KeyPgDeclare|declare]] [[KeyPgFunction|function]] **Cvi** ( [[KeyPgByref|byref]] //str// [[KeyPgAs|as]] [[KeyPgConstQualifier|const]] [[KeyPgString|string]] ) [[KeyPgAs|as]] [[KeyPgInteger|integer]]
[[KeyPgDeclare|declare]] [[KeyPgFunction|function]] **Cvi**<//bits>// ( //expr// [[KeyPgAs|as]] [[DataType]] ) [[KeyPgAs|as]] [[KeyPgInteger|integer]]<//bits//>
##
{{fbdoc item="usage"}}##
//result// = **Cvi**( //sng// )
//result// = **Cvi**( //str// )
//result// = **Cvi**<//bits//>( //expr// )
##
{{fbdoc item="param"}}
##//f//##
A floating-point number with a binary copy of an integer variable stored in it. Its precision (##[[KeyPgSingle|Single]]## or ##[[KeyPgDouble|Double]]##) depends on the size of ##[[KeyPgInteger|Integer]]## on the current platform
##//str//##
A ##[[KeyPgString|String]]## with a binary copy of an integer variable stored in it.
##//bits//##
Specifies a size of integer type to return. The types and sizes of ##//expr//## accepted will depend on the corresponding function called.
##//expr//##
An expression that will be copied into an ##[[KeyPgInteger|Integer]]<//bits//>##.

{{fbdoc item="ret"}}
An ##[[KeyPgInteger|Integer]]## or ##[[KeyPgInteger|Integer]]<//bits//>## variable containing a binary copy of the input expression.

{{fbdoc item="desc"}}
Returns an integer value using the binary data contained in a floating-point value, or a ##[[KeyPgString|String]]##. A value of zero (##0##) is returned if the string contains fewer characters than the size of the return type.

##**Cvi**## can be used to convert strings created with ##[[KeyPgMki|Mki]]##.

This function can also be used to convert ##[[KeyPgInteger|Integer]]##-sized values from a memory or file buffer without the need for a ##[[KeyPgType|Type]]## structure. However, just as with the type structure, special care should be taken when using ##**Cvi**## to convert strings that have been read from a buffer.

##**Cvi**## supports an optional ##<//bits//>## parameter before the argument. If ##//bits//## is ##16##, ##[[KeyPgCvshort|Cvshort]]## will be called instead; if ##//bits//## is ##32##, ##[[KeyPgCvl|Cvl]]## will be called; if ##//bits//## is ##64##, ##[[KeyPgCvlongint|Cvlongint]]## will be called. The return type and accepted argument types will depend on which function is called. See each function's page for more information.

##**Cvi**##'s behaviour changes depending on the size of the ##[[KeyPgInteger|Integer]]## data type on the current platform.
- For 16-bit ##[[KeyPgInteger|Integer]]## (//[[CompilerOptlang|-lang qb]]//), a 16-bit value is returned, and no floating-point types are accepted.
- For 32-bit ##[[KeyPgInteger|Integer]]##, a 32-bit value is returned, and numeric arguments are interpreted as ##[[KeyPgSingle|Single]]## precision values.
- For 64-bit ##[[KeyPgInteger|Integer]]##, a 64-bit value is returned, and numeric arguments are interpreted as ##[[KeyPgDouble|Double]]## precision values.

{{fbdoc item="ex"}}
{{fbdoc item="filename" value="examples/manual/strings/cvi.bas"}}%%(freebasic)
dim i as integer, s as string
s = "ABCD"
i = cvi(s)
print using "s = ""&"""; s
print using "i = _&H&"; hex(i)
%%

{{fbdoc item="lang"}}
- In the //[[CompilerOptlang|-lang qb]]// dialect, ##**Cvi**## expects a 2-byte string, since a QB integer is only 16 bits. Only the first two bytes of the string are used, even if the string happens to be longer than two bytes.
- In the //[[CompilerOptlang|-lang qb]]// dialect, ##**Cvi**## will not take a floating-point argument, since a QB integer is only 16 bits and there is no 16-bit floating-point data type. Instead, ##**Cvi**<32>##/##**Cvi**<64>## or ##[[KeyPgCvl|Cvl]]##/##[[KeyPgCvlongint|Cvlongint]]## may be used.

{{fbdoc item="diff"}}
- In QB an error occurs if the string passed is fewer than two bytes in length.
- QB did not support floating-point arguments.
- QB did not support a ##<//bits//>## parameter.

{{fbdoc item="see"}}
- ##[[KeyPgMki|Mki]]##
- ##[[KeyPgCvshort|Cvshort]]##
- ##[[KeyPgCvl|Cvl]]##
- ##[[KeyPgCvlongint|Cvlongint]]##
- ##[[KeyPgInteger|Integer]]##

{{fbdoc item="back" value="CatPgString|String Functions"}}
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki



sf.net phatcode