Elixir v1.2.6 Bitwise
This module provides macro-based operators that perform calculations on (sets of) bits.
In general, you should use
the Bitwise module as a whole:
iex> use Bitwise
iex> bnot 1
-2
iex> 1 &&& 1
1
When used, it accepts the following options:
:only_operators
- include only operators:skip_operators
- skip operatorsiex> use Bitwise, only_operators: true iex> 1 &&& 1 1
These macros can be used in guards:
iex> use Bitwise
iex> odd? = fn(int) when band(int, 1) == 1 -> true; (_) -> false end
iex> odd?.(1)
true
Summary
Macros
Infix operator; calculates the bitwise AND of its arguments
Infix operator; calculates the result of an arithmetic left bitshift
Infix operator; calculates the result of an arithmetic right bitshift
Infix operator; calculates the bitwise XOR of its arguments
Calculates the bitwise AND of its arguments
Calculates the bitwise NOT of its argument
Calculates the bitwise OR of its arguments
Calculates the result of an arithmetic left bitshift
Calculates the result of an arithmetic right bitshift
Calculates the bitwise XOR of its arguments
Infix operator; calculates the bitwise OR of its arguments
Prefix (unary) operator; calculates the bitwise NOT of its argument
Macros
Infix operator; calculates the result of an arithmetic left bitshift.
iex> 1 <<< 2
4
iex> 1 <<< -2
0
iex> -1 <<< 2
-4
iex> -1 <<< -2
-1
Infix operator; calculates the result of an arithmetic right bitshift.
iex> 1 >>> 2
0
iex> 1 >>> -2
4
iex> -1 >>> 2
-1
iex> -1 >>> -2
-4
Calculates the result of an arithmetic left bitshift.
iex> bsl(1, 2)
4
iex> bsl(1, -2)
0
iex> bsl(-1, 2)
-4
iex> bsl(-1, -2)
-1
Calculates the result of an arithmetic right bitshift.
iex> bsr(1, 2)
0
iex> bsr(1, -2)
4
iex> bsr(-1, 2)
-1
iex> bsr(-1, -2)
-4