Erlang-bitwise-operators

提供:Dev Guides
移動先:案内検索

アーラン-ビットごとの演算子

Erlangで使用できるビット演算子は次のとおりです。

Sr.No. Operator & Description
1

band

これはビット単位の「and」演算子です

2

bor

これはビット単位の「or」演算子です

3

bxor

これはビット単位の「xor」または排他的論理和演算子です

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

次のコードスニペットは、さまざまな演算子の使用方法を示しています。

-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