Erlang - Bitwise Operators


Advertisements

Following are the bitwise operators available in Erlang.

Sr.No. Operator & Description
1

band

This is the bitwise “and” operator

2

bor

This is the bitwise “or” operator

3

bxor

This is the bitwise “xor” or Exclusive or operator

4

bnot

This is the bitwise negation operator

Following is the truth table showcasing these operators −

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

The following code snippet shows how the various operators can be used.

Example

-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]).

The output of the above program will be −

Output

76
0
-111101
111100
erlang_operators.htm
Advertisements