LOTUSSCRIPT 言語


ビット単位演算子
ビット単位演算子の Not と数値オペランドで構成される式は、Integer 型または Long 型の値 (またはオペランドが NULL の場合は NULL) に評価されます。この値は、オペランドの 2 進表記のビットの値を逆にした結果 (補数) です。

以下に例を示します。

anInt% = 8
Print Bin$(anInt%)
' Output:1000
anotherInt% = Not anInt%
Print Bin$(anotherInt%)
' Output: 11111111 11111111 11111111 11110111

2 つの数値オペランドと 1 つのビット単位演算子で構成される式は、Integer 型または Long 型の値 (または一方のオペランドが NULL の場合は NULL) に評価されます。ビット単位演算の結果のデータ型を決定する規則は、次のとおりです。


オペランドが 2 つの式のビット単位演算の結果を次に示します。
演算子expr1 のビット nexpr2 のビット n結果のビット n
And0 0 0
0 1 0
1 0 0
1 1 1
Or0 0 0
0 1 1
1 0 1
1 1 1
Xor0 0 0
0 11
1 0 1
1 1 0
Eqv0 0 1
0 1 0
1 0 0
1 1 1
Imp0 0 1
0 1 1
1 0 0
1 1 1
以下に例を示します。

anInt% = 10
anotherInt% = 5
aDouble# = 2.6
Print Bin$(anInt%)
' Output:1010
Print Bin$(anotherInt%)
' Output:101
Print Bin$(aDouble#)
' Output:11

theResult% = anInt% And anotherInt%
Print Bin$(theResult%)
' Output:0
theResult% = anInt% And aDouble#
Print Bin$(theResult%)
' Output:10

theResult% = anInt% Or anotherInt%
Print Bin$(theResult%)
' Output:1111
theResult% = anInt% Or aDouble#
Print Bin$(theResult%)
' Output:1011

theResult% = anInt% Xor anotherInt%
Print Bin$(theResult%)
' Output:1111
theResult% = anInt% Xor aDouble#
Print Bin$(theResult%)
' Output:1001
theResult% = anInt% Eqv anotherInt%
Print Bin$(theResult%)
' Output:11111111 11111111 11111111 11110000
theResult% = anInt% Eqv aDouble#
Print Bin$(theResult%)
' Output:11111111 11111111 11111111 11110110

theResult% = anInt% Imp anotherInt%
Print Bin$(theResult%)
' Output:11111111 11111111 11111111 11110101
theResult% = anInt% Imp aDouble#
Print Bin$(theResult%)
' Output: 11111111 11111111 11111111 11110111

関連項目