BitwiseOperations

From Elixir Wiki
Jump to navigation Jump to search

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]

See Also[edit]

References[edit]

<references />