CBYTE
- 来源: https://www.freebasic.net/wiki/wikka.php?wakka=KeyPgCbyte
- 最后更新: 2016-03-12
将数值或字符串表达式转换为 Byte 类型。
语法
vb
declare function Cbyte ( byval expression as datatype ) as byte
Type typename
declare operator cast ( ) as byte
End Type用法
vb
result = Cbyte( numeric expression )
result = Cbyte( string expression )
result = Cbyte( user defined type )参数
expression
要转换为 Byte 值的数值、字符串或指针表达式。
datatype
任何数值、字符串或指针数据类型。
typename
用户自定义类型。
返回值
Byte 值。
说明
Cbyte 函数舍去小数部分并返回 8 位 Byte 值。该函数不检查溢出,对于小于 -128 或大于 127 的值,结果是未定义的。
函数名可以理解为"转换为字节型"(Convert to Byte)。
如果参数是字符串表达式,则使用 Valint 将其转换为数值。
示例
start GeSHi
vb
' Using the CBYTE function to convert a numeric value
'Create an BYTE variable
Dim numeric_value As Byte
'Convert a numeric value
numeric_value = CByte(-66.30)
'Print the result, should return -66
Print numeric_value
Sleepend GeSHi
方言差异
- 在 -lang qb 方言中不可用,除非使用别名
__Cbyte引用。
与 QB 的差异
- FreeBASIC 新增特性
另请参阅
CubyteCshortCushortCintCuintClngCulngClngintCulngintCsngCdbl
返回 目录