Repository navigation
Cvi
Home › String Functions › CVI
Reads an integer back from a string of its bytes.
32-bit:
Declare Function CVI ( ByVal f As Single ) As Integer
64-bit:
Declare Function CVI ( ByVal f As Double ) As Integer
Declare Function CVI ( ByRef str As Const String ) As Integer
Declare Function CVI<bits> ( expr As DataType ) As Integer<bits>fstrbitsexprexpr
Returns an integer value using the binary data contained in a floating-point value, or a 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 MKI.
This function can also be used to convert Integer-sized values from a memory or file buffer without the need for a 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, CVShort will be called instead; if bits is 32, CVL will be called; if bits is 64, 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 Integer data type on the current platform.
- For 16-bit
Integer(-lang qb), a 16-bit value is returned, and no floating-point types are accepted. For 32-bitInteger, a 32-bit value is returned, and numeric arguments are interpreted asSingleprecision values.
For 64-bitInteger, a 64-bit value is returned, and numeric arguments are interpreted asDoubleprecision values.
An Integer or Integer<bits> variable containing a binary copy of the input expression.
result = CVI( sng )
result = CVI( str )
result = CVI<bits>( expr )- In the -lang qb dialect,
CVIexpects 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 -lang qb dialect,CVIwill 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>orCVL/CVLongIntmay be used.
- 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.
Dim i As Integer, s As String
s = "ABCD"
i = CVI(s)
Print Using "s = ""&"""; s
Print Using "i = _&H&"; Hex(i)Category: String Functions
Kind: function
Reproduced from the FreeBASIC Wiki Manual under the GNU Free Documentation License 1.3 — with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts. Copyright © the FreeBASIC project and wiki contributors. See License.
tiko-lang · Home · Feature Index · Keyword Index · License
FreeBASIC manual pages reproduced under the GNU FDL 1.3.
- Generics
- Interfaces
- For Each
- Iterators
- Tuples
- Array Results
- Defer
- Lambdas
- Block Strings
- String Slices
- Embed
- Typed Variadics
- C Header Import
- Foreign Library Linking
- UString
- Fixed-Width Types
- Nullptr
- String Library
- Format
- Array
- Map
- Set
- LinkedList
- OrderedMap
- OrderedSet
- Sorting
- Optional
- Result
- Smart Pointers
- Date and Time (Chrono)
- Filesystem
- File Streams
- Config (INI and TOML)
- Codec
- Hash
- UUID
- OS
- Process
- Net
- HTTP and TLS
- Math Library
- Finance
- Logging
- Terminal TUI Library
- PsControls
- tkControls
- sys/win
- Goroutines and Channels
- LLVM Backend
- tiko build
- TIKO_COMPILER
- Variable Declarations
- Standard Data Types
- User Defined Types
- Procedures
- Operators
- Control Flow Statements
- Converting Data Types
- Array Functions
- String Functions
- Mathematical Functions
- Bit Manipulation
- Date and Time Functions
- File I/O Functions
- Console Functions
- User Input (Runtime Library)
- User Input Functions (Graphics Library)
- Screen Functions
- 2D Drawing Functions
- Graphics Library Reference
- Graphics Keyword List
- Memory Functions
- Threading Support Functions
- Error Handling Functions
- Operating System Functions
- Preprocessor
- Intrinsic Defines
- Miscellaneous Keywords
- Modularizing