Erlang – Bitwise Operators

Erlang Bitwise Operators

Following are the bitwise operators available in Erlang.

Sr.No.Operator & Description
1band
This is the bitwise “and” operator
2bor
This is the bitwise “or” operator
3bxor
This is the bitwise “xor” or Exclusive or operator
4not
This is the bitwise negation operator

Following is the truth table showcasing these operators −

pqp & qp | qp ^ q
00000
01011
11110
10011

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

Next Topic : Click Here

This Post Has 2 Comments

Leave a Reply