Operator Not(取反/按位补)
- 来源: https://www.freebasic.net/wiki/wikka.php?wakka=KeyPgOpNot
- 最后更新: 2016-03-13
返回数值的按位取反(按位补)
语法
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')
下面的真值表演示了布尔取反运算的所有组合:
| 右操作数位 | 结果 |
|---|---|
| 0 | 1 |
| 1 | 0 |
此运算符可以为用户定义类型重载。
示例
start GeSHi
vb
' 在数值上使用 NOT 运算符
Dim numeric_value As Byte
numeric_value = 15 '00001111
'结果 = -16 = 11110000
Print Not numeric_valueend 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 的区别
- 无
参见
返回 目录