Erlang 位運算子



以下是 Erlang 中可用的位運算子。

序號 運算子及描述
1

band

這是按位“與”運算子

2

bor

這是按位“或”運算子

3

bxor

這是按位“異或”或“異或”運算子

4

bnot

這是按位取反運算子

下表展示了這些運算子的真值表:

p q p & q p | q p ^ q
0 0 0 0 0
0 1 0 1 1
1 1 1 1 0
1 0 0 1 1

以下程式碼片段演示瞭如何使用各種運算子。

示例

-module(helloworld). 
-export([start/0]). 

start() -> 
   io:fwrite("~w~n",[00111100 band 00001101]), 
   io:fwrite("~w~n",[00111100 bxor 00111100]), 
   io:fwrite("~w~n",[bnot 00111100]), 
   io:fwrite("~w~n",[00111100 bor 00111100]).

以上程式的輸出將是:

輸出

76
0
-111101
111100
erlang_operators.htm
廣告
© . All rights reserved.