Skip to content

运算符 OR(包含析取)


返回两个数值的按位或(包含析取)

语法

` declare operator Or ( byref lhs as T1, byref rhs as T2 ) as Ret

`

用法

` result = lhs Or rhs

`

参数

lhs

左侧表达式。

T1

任意数值或布尔类型。

rhs

右侧表达式。

T2

任意数值或布尔类型。

Ret

数值或布尔类型(随 T1T2 变化)。

返回值

返回两个操作数的按位析取结果。

描述

该运算符返回其操作数的按位析取结果,这是一个逻辑运算,根据操作数的位来设置结果中的位(对于布尔值转换为整数,false 或 true 的布尔值变为 0 或 -1 的整数值)。

下方真值表展示了布尔析取运算的所有组合:

左侧位右侧位结果
000
101
011
111

不执行短路求值——始终对两个表达式求值。

返回类型取决于所传递值的类型。ByteUbyte 和浮点类型值首先被转换为 Integer。如果左侧和右侧类型仅在有无符号方面不同,则返回类型与左侧类型(T1)相同,否则返回两种类型中较大的那个。只有当左侧和右侧类型都是 Boolean 时,返回类型才也是 Boolean

该运算符可为用户自定义类型重载。

示例

start GeSHi

vb
' Using the OR operator on two numeric values
Dim As UByte numeric_value1, numeric_value2
numeric_value1 = 15 '00001111
numeric_value2 = 30 '00011110

'Result =  31  =     00011111
Print numeric_value1 Or numeric_value2
Sleep

end GeSHi

start GeSHi

vb
' Using the OR operator on two conditional expressions
Dim As UByte numeric_value
numeric_value = 10

If numeric_value = 5 Or numeric_value = 10 Then Print "Numeric_Value equals 5 or 10"
Sleep

' This will output "Numeric_Value equals 5 or 10" because
' while the first condition of the first IF statement is false, the second is true

end GeSHi

方言差异

  • -lang qb 方言中,该运算符不能被重载。

与 QB 的差异

参见

返回 目录

基于 FreeBASIC 官方文档翻译 如有侵权请联系我们删除
FreeBASIC 是开源项目,与微软公司无隶属关系