BitwiseOperations
Bitwise Operations[edit]
Bitwise operations are fundamental operations that manipulate individual bits in a binary representation of data. In Elixir, bitwise operations can be performed on integers to perform various tasks, such as extracting specific bits, setting or clearing bits, or performing logical operations.
Bitwise AND[edit]
The bitwise AND operation, denoted by the ampersand (&) symbol, compares corresponding bits of two integers and returns a new integer with the bits set to 1 only if both bits are 1.
Bitwise OR[edit]
The bitwise OR operation, denoted by the vertical bar (|) symbol, compares corresponding bits of two integers and returns a new integer with the bits set to 1 if either of the corresponding bits is 1.
Bitwise XOR[edit]
The bitwise XOR (exclusive OR) operation, denoted by the caret (^) symbol, compares corresponding bits of two integers and returns a new integer with the bits set to 1 if the corresponding bits differ.
Bitwise NOT[edit]
The bitwise NOT operation, denoted by the tilde (~) symbol, flips the bits of the integer. Each 0 bit becomes 1, and each 1 bit becomes 0.
Left Shift[edit]
The left shift operation, denoted by the double less than (<<) symbol, shifts the bits of an integer to the left by a specified number of positions.
Right Shift[edit]
The right shift operation, denoted by the double greater than (>>) symbol, shifts the bits of an integer to the right by a specified number of positions.
Examples[edit]
- Bitwise AND example: Template:Code
- Bitwise OR example: Template:Code
- Bitwise XOR example: Template:Code
- Bitwise NOT example: Template:Code
- Left shift example: Template:Code
- Right shift example: Template:Code
See Also[edit]
- LogicOperations - Introduction to logical operations in Elixir.
- BinaryManipulation - Manipulating binary data in Elixir.
- BitwiseOperationsInOtherLanguages - Comparison of bitwise operations in other programming languages.
References[edit]
<references />