Skip to content

Operator Not(取反/按位补)


返回数值的按位取反(按位补)

语法

vb
declare operator Not ( byref rhs as byte ) as integer
declare operator Not ( byref rhs as ubyte ) as integer
declare operator Not ( byref rhs as single ) as integer
declare operator Not ( byref rhs as double ) as integer

declare operator Not ( byref rhs as T ) as T

用法

result = Not rhs

参数

rhs

右侧表达式。

T

任何数值或布尔类型。

返回值

返回其操作数的按位补。

描述

此运算符返回其操作数的按位补,这是一种逻辑运算,根据操作数的位设置结果中的位。

(对于布尔类型,'Not false' 返回 'true','Not true' 返回 'false')

下面的真值表演示了布尔取反运算的所有组合:

右操作数位结果
01
10

此运算符可以为用户定义类型重载。

示例

start GeSHi

vb
' 在数值上使用 NOT 运算符

Dim numeric_value As Byte
numeric_value = 15 '00001111

'结果 = -16 =     11110000
Print Not numeric_value

end GeSHi

start GeSHi

vb
' 在条件表达式上使用 NOT 运算符
Dim As UByte numeric_value1, numeric_value2
numeric_value1 = 15
numeric_value2 = 25

If Not numeric_value1 = 10 Then Print "Numeric_Value1 is not equal to 10"
If Not numeric_value2 = 25 Then Print "Numeric_Value2 is not equal to 25"

' 这将输出 "Numeric_Value1 is not equal to 10",因为
' 第一个 IF 语句为假。
' 不会输出第二个 IF 语句的结果,因为该条件为真。

end GeSHi

方言差异

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

与 QB 的区别

参见

返回 目录

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